Description Usage Arguments Details Value References See Also Examples
rapply
is a recursive version of lapply
.
1 2 |
object |
A list. |
f |
A function of a single argument. |
classes |
A character vector of |
deflt |
The default result (not used if |
how |
A character string partially matching the three possibilities given: see ‘Details’. |
... |
additional arguments passed to the call to |
This function has two basic modes. If how = "replace"
, each
element of the list which is not itself a list and has a class
included in classes
is replaced by the result of applying
f
to the element.
If the mode is how = "list"
or how = "unlist"
, the list
is copied, all non-list elements which have a class included in
classes
are replaced by the result of applying f
to the
element and all others are replaced by deflt
. Finally, if
how = "unlist"
, unlist(recursive = TRUE)
is called on
the result.
The semantics differ in detail from lapply
: in
particular the arguments are evaluated before calling the C code.
If how = "unlist"
, a vector, otherwise a list of similar
structure to object
.
Chambers, J. A. (1998)
Programming with Data.
Springer.
(rapply
is only described briefly there.)
1 2 3 4 5 6 7 8 9 | X <- list(list(a = pi, b = list(c = 1:1)), d = "a test")
rapply(X, function(x) x, how = "replace")
rapply(X, sqrt, classes = "numeric", how = "replace")
rapply(X, nchar, classes = "character",
deflt = as.integer(NA), how = "list")
rapply(X, nchar, classes = "character",
deflt = as.integer(NA), how = "unlist")
rapply(X, nchar, classes = "character", how = "unlist")
rapply(X, log, classes = "numeric", how = "replace", base = 2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.