[R] Quick q. on lists

Erik Iverson eriki at ccbr.umn.edu
Thu Aug 19 17:47:23 CEST 2010



Jonathan wrote:
> Hi All,
>     Anyone know how to quickly query some summary information on the
> components of a list?
> 
> For example, I have a list that contains dataframes (originally
> generated by using split() on one large data frame).
> 
> 
> I simply want to know the number of rows in the longest dataframe from the list.
> 
> Example, if my list has 3 data frames, and the first has 2 rows, the
> second 8 rows, and the third 3 rows, I want to ask something like:
> 
> 
> max(nrow(myList))
> which would ideally return "8".
> 

max(sapply(myList, nrow))

> 
> but this is obviously wrong syntax.
> 
> Currently, I'm looping through each of the data frames in the list,
> searching for the max rows, but I'm sure there must be a faster way.
> 
> Thanks,
> Jonatahn
> 
> ______________________________________________
> 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.



More information about the R-help mailing list