[R] rapply on a data.frame
Michael Hoffman
b3i4old02 at sneakemail.com
Sun Feb 24 22:01:58 CET 2008
Michael Hoffman wrote:
> Is it possible to get something like rapply for a data.frame?
On second thought, I can do something like this:
happly <- function(x, fun) {
if (class(x) == "list") {
lapply(x, happly, fun)
} else {
fun(x)
}
}
> happly(list(a=list(c=mtcars, d=Titanic), x=mtcars), nrow)
$a
$a$c
[1] 32
$a$d
[1] 4
$x
[1] 32
Better suggestions welcome.
More information about the R-help
mailing list