[R] Extracting data from a list of matrices

Henrique Dallazuanna wwwhsd at gmail.com
Thu Jan 14 17:27:46 CET 2010


Try this:

lapply(l, '[', 1, 1)


On Thu, Jan 14, 2010 at 2:22 PM, Hubert Colt <hubert.colt at gmail.com> wrote:
> Hi,
>
> Apologies in advance for the basic nature of my question. I am still very
> much a rookie when it comes to R. Having googled it, checked Nabble and
> trial/error to the best of my ability, I have yet to find an easy solution.
>
> I am currently working with a list of 5x5 matrices, and want to extract a
> list consisting of the first number of each matrix.
>
> In other words I want to go from:
>
> [[1]]
>              [,1]          [,2]          [,3]          [,4]          [,5]
> [1,]             a             X             X             X             X
> [2,]             X             X             X             X             X
> [3,]             X             X             X             X             X
> [4,]             X             X             X             X             X
> [5,]             X             X             X             X             X
>
> [[2]]
>              [,1]          [,2]          [,3]          [,4]          [,5]
> [1,]             b             X             X             X             X
> [2,]             X             X             X             X             X
> [3,]             X             X             X             X             X
> [4,]             X             X             X             X             X
> [5,]             X             X             X             X             X
>
> etc.
>
> to a new list:
>
>      [,1]
> [[1]]    a
> [[2]]    b
>
> etc.
>
> Any help will be greatly appreciated.
>
> -Hubert
>
>        [[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