[R] subsetting a list of matrices

Gabor Grothendieck ggrothendieck at gmail.com
Tue Feb 28 18:29:55 CET 2006


Try this:

lapply(z, "[", 2:3, TRUE)

On 2/28/06, Federico Calboli <f.calboli at imperial.ac.uk> wrote:
> Hi All,
>
> I have a list of matrices:
>
> > x
>     [,1] [,2]
> [1,]    1    4
> [2,]    2    5
> [3,]    3    6
> > y
>     [,1] [,2] [,3] [,4] [,5] [,6]
> [1,]   18   21   24   27   30   33
> [2,]   19   22   25   28   31   34
> [3,]   20   23   26   29   32   35
> > z =list(x,y)
>
> I want to create a second list that is has a subset each matrix in the
> list subsetting so I get the 2nd and 3rd row of each (and all columns).
>
> How could I do that (apart from looping)?
>
> Regards,
>
> Federico Calboli
>
> --
> Federico C. F. Calboli
> Department of Epidemiology and Public Health
> Imperial College, St Mary's Campus
> Norfolk Place, London W2 1PG
>
> Tel  +44 (0)20 7594 1602     Fax (+44) 020 7594 3193
>
> f.calboli [.a.t] imperial.ac.uk
> f.calboli [.a.t] gmail.com
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list