Learn R Programming

ldat (version 0.3.3)

elementwise: 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

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

# }

Run the code above in your browser using DataLab