elementwise: Apply a function to each element of an lvec

View source: R/elementwise.R

elementwiseR Documentation

Apply a function to each element of an lvec

Description

Apply a function to each element of an lvec

Usage

elementwise(x, fun, ...)

Arguments

x

an object of type lvec.

fun

the function to apply to the lvec. This function receives chunks of the lvec (which are regular R-vector) and should return a (R) vector of the same length as its input.

...

passed on to fun.

Value

Returns a link{lvec} of the same length as the input. The type is determined by the output of fun.

Examples

# Calculate square root of lvec
x <- as_lvec(1:10)
y <- elementwise(x, sqrt)
# of course, this is already implemented
sqrt(x)


djvanderlaan/lvec_stats documentation built on Oct. 4, 2022, 7:02 p.m.