aggregators: Combine aggregate functions and s

wrapper - s and summary funsR Documentation

Combine aggregate functions and s

Description

[summary function_*] functions are simple wrappers of aggregate function and the s function. s removes all non-values, i.e. NA,Inf,NaN from a vector. However, if the length is 0 it returns NA. The result is then passed to the corresponding aggregation function. For example, min_(x) is identical to min(s(x)). Please read vignette("s") for more information.

Usage

max_(.x, ignore_na = TRUE)

min_(.x, ignore_na = TRUE)

sum_(.x, ignore_na = TRUE)

mean_(.x, ignore_na = TRUE)

median_(.x, ignore_na = TRUE)

sd_(.x, ignore_na = TRUE)

var_(.x, ignore_na = TRUE)

first_(.x, ignore_na = TRUE)

last_(.x, ignore_na = TRUE)

first_non_na(.x)

squeeze(.x, ignore_na = FALSE)

squeeze_(.x, ignore_na = TRUE)

Arguments

.x

a single vector

ignore_na

if false missing values are not omitted.

Details

'first_non_na' is a faster version of 'first' since it only search for a non NA value until it finds one. 'squeeze' on the other hand checks if all elements are equal and then returns only that value.

Value

a single aggregated value

See Also

vignette("convert"), vignette("hablar")

Examples

## sum_ on non-rational numeric vector
vector <- c(7, NaN, -Inf, 4)
sum_(vector)

## Min of vector with length 0
vector <- c()
# With a wrapped s
min_(vector)

## Max of vector with only NA
# With a wrapped s
max_(vector)

## Use of s when NA should not be removed
vector <- c(7, Inf, NA, 4)
# With a wrapped s
sum_(vector, ignore_na = FALSE)


hablar documentation built on March 31, 2023, 11:54 p.m.