Skip to content

This generic provides a common dispatch mechanism for all regular unary mathematical functions. It is used as a common wrapper around many of the Summary group generics, the Math group generics, and a handful of other mathematical functions like mean() (but not var() or sd()).

Usage

vec_math(.fn, .x, ...)

vec_math_base(.fn, .x, ...)

Arguments

.fn

A mathematical function from the base package, as a string.

.x

A vector.

...

Additional arguments passed to .fn.

Details

vec_math_base() is provided as a convenience for writing methods. It calls the base .fn on the underlying vec_data().

Included functions

Note that median() is currently not implemented, and sd() and var() are currently not generic and so do not support custom classes.

See also

vec_arith() for the equivalent for the arithmetic infix operators.

Examples

x <- new_vctr(c(1, 2.5, 10))
x
#> <vctrs_vctr[3]>
#> [1]  1.0  2.5 10.0

abs(x)
#> <vctrs_vctr[3]>
#> [1]  1.0  2.5 10.0
sum(x)
#> <vctrs_vctr[1]>
#> [1] 13.5
cumsum(x)
#> <vctrs_vctr[3]>
#> [1]  1.0  3.5 13.5