average: Average

View source: R/average.R

averageR Documentation

Average

Description

Computes arithmetic means

Usage

average(x, min_valid, max_na, func = mean(.))

Arguments

x

Vector

min_valid

Minimal number of valid values that is required for calculating the mean. A value between 0 and 1 indicates a proportion of values (e.g., 0.5 = 50 percent of values have to be valid).

max_na

Maximum number of NAs that are allowed before returning NA. A value between 0 and 1 indicates a proportion of values (e.g., 0.5 = 50 percent NAs are allowed).

func

Function without the header ⁠function(.)⁠ for calculating the average.

Examples

dat <- c(1:5, NA, NA)
average(dat, min_valid = 5)
average(dat, min_valid = 6)
average(dat, max_na = 2)
average(dat, max_na = 1)
average(dat, min_valid = 0.5, func = median(.))
average(dat, min_valid = 0.9)

jazznbass/wmisc documentation built on Oct. 29, 2024, 5:42 p.m.