[R] Creating lists from matrices

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.ac.be
Thu Nov 25 10:28:11 CET 2004


Hi Alexander,

you could try this:

(my.matrix <- matrix(LETTERS[1:9], 3, byrow=TRUE))
split(my.matrix, row(my.matrix))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Alexander Sokol" <alexandersokol at ofir.dk>
To: <r-help at stat.math.ethz.ch>
Sent: Thursday, November 25, 2004 10:12 AM
Subject: [R] Creating lists from matrices


> Hello,
>
> I am using R 1.9.1 on Windows 2000 SP4. I have the following 
> problem:
>
> Say I have a matrix,
>
>>my.matrix
>       [,1]   [,2]   [,3]
> [1,]   "A"   "B"   "C"
> [2,]   "D"   "E"   "F"
> [3,]   "G"   "H"   "I"
>
> I would like to apply an operation to this matrix which returns a 
> list my.list
> containing the following 3 elements,
>
>>my.list
> [[1]]
> [1] "A" "B" "C"
> [[2]]
> [2] "D" "E" "F"
> [[3]]
> [3] "G" "H" "I"
>
> That is, each row of the original matrix is turned into a vector and 
> these
> vectors are collected to a list. How do I do this?
>
> Thanks,
> Alexander
>
> ______________________________________________
> 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