[R] extracting one element from all list elements

Henrique Dallazuanna wwwhsd at gmail.com
Wed Sep 16 13:35:57 CEST 2009


Try this:

 sapply(theList, '[[', 'A')

On Wed, Sep 16, 2009 at 8:34 AM, Rainer M Krug <r.m.krug at gmail.com> wrote:
> Hi
>
> I have a list which cosists out of dataframes of the same structure. Now I
> want to extract one column (let's say column "A") from all dataframes and
> have them in a matrix (or dataframe).
>
> At the moment I am doiong:
>
> d <- data.frame(A=runif(100), B=rnorm(100))
> theList <- list(e1=d, e2=d, e3=d, e4=d)
> f <- sapply(theList, function(l){l$A} )
>
> But I am sure ther is a more elegant way?
>
> Rainer
>
> --
> Rainer M. Krug, Centre of Excellence for Invasion Biology, Stellenbosch
> University, South Africa
>
>        [[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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list