Skip to content
Prev 59801 / 398502 Next

Creating lists from matrices

Hi,

One could use the following:

 >  mm=matrix(letters[1:9],ncol=3,byrow=TRUE)
 >  lapply(apply(mm,1,list),function(el)el[[1]])
[[1]]
[1] "a" "b" "c"

[[2]]
[1] "d" "e" "f"

[[3]]
[1] "g" "h" "i"

You could also have a look at as.data.frame.matrix, which transform a 
matrix into a data.frame efficiently. data.frames are internaly structured 
as lists...

Eric
At 10:12 25/11/2004, Alexander Sokol wrote:
Eric Lecoutre
UCL /  Institut de Statistique
Voie du Roman Pays, 20
1348 Louvain-la-Neuve
Belgium

tel: (+32)(0)10473050
lecoutre at stat.ucl.ac.be
http://www.stat.ucl.ac.be/ISpersonnel/lecoutre

If the statistics are boring, then you've got the wrong numbers. -Edward 
Tufte