[R] taking rows from data.frames in list to form new data.frame?

Hadley Wickham hadley at rice.edu
Thu Apr 21 14:02:32 CEST 2011


On Wed, Apr 20, 2011 at 6:36 PM, Dennis Murphy <djmuser at gmail.com> wrote:
> Hi:
>
> Perhaps you're looking for subset()? I'm not sure I understand the
> problem completely, but is
>
> do.call(rbind, lapply(database, function(df) subset(df, Symbol == 'IBM')))
>
> or
>
> library(plyr)
> ldply(lapply(database, function(df) subset(df, Symbol == 'IBM'), rbind)

That's a bit redundant.  All you need is:

ldply(database, function(df) subset(df, Symbol == 'IBM'))

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list