Learn R Programming

tidyna (version 0.4.0)

summary-functions: NA-aware Summary Functions

Description

Drop-in replacements for summary functions that default to na.rm = TRUE and warn when missing values are removed.

Usage

mean(x, na.rm = TRUE, all_na = NULL, ...)

sum(x, na.rm = TRUE, all_na = NULL, ...)

prod(x, na.rm = TRUE, all_na = NULL, ...)

sd(x, na.rm = TRUE, all_na = NULL, ...)

var(x, na.rm = TRUE, all_na = NULL, ...)

median(x, na.rm = TRUE, all_na = NULL, ...)

quantile(x, na.rm = TRUE, all_na = NULL, ...)

Value

The computed summary statistic.

Arguments

x

A numeric vector.

na.rm

Logical. Should missing values be removed? Default TRUE.

all_na

Character. What to do when all values are NA: "error" (default) throws an error, "base" returns what base R does with na.rm = TRUE (e.g., NaN for mean(), 0 for sum()), "na" returns NA. If NULL, uses getOption("tidyna.all_na", "error").

...

Additional arguments passed to the base function.

Examples

Run this code
x <- c(1, 2, NA, 4)
mean(x)

# Suppress warnings
options(tidyna.warn = FALSE)
mean(x)
options(tidyna.warn = TRUE)

# Control all-NA behavior
mean(c(NA, NA), all_na = "na")

Run the code above in your browser using DataLab