Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rapply2d

Recursively Apply a Function to a List of Data Objects


Description

rapply2d is a recursive version of lapply with two key differences to rapply: (1) Data frames are considered as final objects, not as (sub-)lists, and (2) the result is never simplified / unlisted.

Usage

rapply2d(l, FUN, ..., classes = "data.frame")

Arguments

l

a list.

FUN

a function that can be applied to all elements in l.

...

additional elements passed to FUN.

classes

character. These are classes of list-based objects inside l which FUN should be applied to. Note that FUN is also applied to all non-list elements in l. It is thus quite different from the classes argument to rapply.

Value

A list of the same structure as l, where FUN was applied to all final (atomic) elements and list-based objects of a class included in classes.

See Also

Examples

l <- list(mtcars, list(mtcars, as.matrix(mtcars)))
rapply2d(l, fmean)
unlist2d(rapply2d(l, fmean))

collapse

Advanced and Fast Data Transformation

v1.5.3
GPL (>= 2) | file LICENSE
Authors
Sebastian Krantz [aut, cre], Matt Dowle [ctb], Arun Srinivasan [ctb], Laurent Berge [ctb], Dirk Eddelbuettel [ctb], Josh Pasek [ctb], Kevin Tappe [ctb], R Core Team and contributors worldwide [ctb], Martyn Plummer [cph], 1999-2016 The R Core Team [cph]
Initial release
2021-03-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.