vec_math: Mathematical operations

View source: R/numeric.R

vec_mathR Documentation

Mathematical operations


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()).


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

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



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


A vector.


Additional arguments passed to .fn.


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

Included functions

  • From the Summary group generic: prod(), sum(), any(), all().

  • From the Math group generic: abs(), sign(), sqrt(), ceiling(), floor(), trunc(), cummax(), cummin(), cumprod(), cumsum(), log(), log10(), log2(), log1p(), acos(), acosh(), asin(), asinh(), atan(), atanh(), exp(), expm1(), cos(), cosh(), cospi(), sin(), sinh(), sinpi(), tan(), tanh(), tanpi(), gamma(), lgamma(), digamma(), trigamma().

  • Additional generics: mean(), is.nan(), is.finite(), is.infinite().

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.


x <- new_vctr(c(1, 2.5, 10))


vctrs documentation built on May 29, 2024, 11:39 a.m.