[R] subsetting a list of dataframes

Jannis bt_jannis at yahoo.de
Tue May 17 22:41:41 CEST 2011


Have a look at lapply(). Something like:

entries.with.nrows=lapply(data,function(x)dim(x)[1]>1)

should give you a vector with the elements of the list that you seek marked with TRUE.

This vector can then be used to extract a subset from your list by:

data.reduced=data[entries.with.nrows]

Or similar....


HTH
Jannis

--- Lara Poplarski <larapoplarski at gmail.com> schrieb am Di, 17.5.2011:

> Von: Lara Poplarski <larapoplarski at gmail.com>
> Betreff: [R] subsetting a list of dataframes
> An: r-help at r-project.org
> Datum: Dienstag, 17. Mai, 2011 20:24 Uhr
> Hello All,
> 
> I have a list of dataframes, and I need to subset it by
> keeping only those
> dataframes in the list that meet a certain criterion.
> Specifically, I need
> to generate a second list which only includes those
> dataframes whose number
> of rows is > 1.
> 
> Could someone suggest how to do this? I have come close to
> what I need with
> loops and such, but there must be a less clumsy way...
> 
> Many thanks,
> Lara
> 
>     [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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