lapply: Apply a function over a list-like object preserving its...

lapplyR Documentation

Apply a function over a list-like object preserving its attributes

Description

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'.

Usage

lapply(x, FUN, ...)

## Default S3 method:
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))

# To preserve attributes
class(lapply(x, mean, keep.attr = TRUE))

genomaths/MethylIT documentation built on Feb. 3, 2024, 1:24 a.m.