Re: [R] rapply on a data.frame

From: Michael Hoffman <b3i4old02_at_sneakemail.com>
Date: Sun, 24 Feb 2008 21:01:58 +0000

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.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 24 Feb 2008 - 21:06:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 24 Feb 2008 - 21:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive