hi feng,
a possible solution is

b1<-apply(a,2,list)

and possibly

lapply(b1,unlist)

if you want exactly the output equal to "list(a[, 1], a[, 2])"

best,
vito

Il 18/01/2011 13.53, Feng Li ha scritto:
Dear R,

Is there an efficient way to make a list that each element is from the
corresponding column of a matrix. For example, if I have a matrix "a"

a<- matrix(1:10, 5, 2)
a
      [,1] [,2]
[1,]    1    6
[2,]    2    7
[3,]    3    8
[4,]    4    9
[5,]    5   10

I would like to have a list "b" like this

b<- list(a[, 1], a[, 2])
b
[[1]]
[1] 1 2 3 4 5

[[2]]
[1]  6  7  8  9 10


Thanks in advance!


Feng


--
====================================
Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 23895240
fax: 091 485726/485612
http://dssm.unipa.it/vmuggeo

______________________________________________
R-help@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.

Reply via email to