lapply returns a list of the same length as 'x', each element of which is the result of applying FUN to the corresponding element of 'x'.

lapply(x, FUN, ...)

# S3 method for default
lapply(x, FUN, keep.attr = FALSE, ...)

Arguments

x

A list-like or vector-like object

FUN, ...

See ?base::lapply for a description of these arguments.

keep.attr

Logic. If TRUE, then the original attributes from 'x' are preserved in the returned list. Default is FALSE.

Value

Same as in ?base::lapply if keep.attr = FALSE. Otherwise same values preserving original attributes from 'x'.

See also

base::lapply

Examples

# Create a list
x <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE))
class(x) <- 'nice'

# compute the list mean for each list element using 'base::lapply'
class(lapply(x, mean))
#> [1] "list"

# To preserve attributes
class(lapply(x, mean, keep.attr = TRUE))
#> [1] "nice"