[R] How to convert a list to a matrix
Romain Francois
francoisromain at free.fr
Thu Feb 3 17:56:16 CET 2005
Le 03.02.2005 16:42, Romain Francois a écrit :
> Hello,
>
> try the following :
>
>> l <- list(NULL)
>> l[[1]] <- 1:2
>> l[[2]] <- 2:3
>> l[[3]] <- 4:5
>> l
>
> [[1]]
> [1] 1 2
>
> [[2]]
> [1] 2 3
>
> [[3]]
> [1] 4 5
>
>> matrix(unlist(l),ncol=2)
>
Sorry, i forgot the byrow argument, the correct comand was :
matrix(unlist(l),ncol=2,byrow=T)
I need some coffee. :-)
Romain
> [,1] [,2]
> [1,] 1 3
> [2,] 2 4
> [3,] 2 5
>
>
> Is that what you want ?
>
> Romain
> Le 03.02.2005 16:08, michael watson (IAH-C) a écrit :
>
>> Hi
>>
>> Sorry to ask such a basic question. I have a list, each element of
>> which is a vector of two values. What I actually want is a matrix with
>> two columns, and one row per element of the list. Obviously I have
>> tried as.matrix(), and as.vector() but I didn't expect the latter to
>> work.
>>
>> I feel so lame asking this. Any suggestions?
>>
>> Mick
>>
>>
>>
>
--
Romain FRANCOIS : francoisromain at free.fr
page web : http://addictedtor.free.fr/ (en construction)
06 18 39 14 69 / 01 46 80 65 60
_______________________________________________________
Etudiant en 3eme année
Institut de Statistique de l'Université de Paris (ISUP)
Filière Industrie et Services
http://www.isup.cicrp.jussieu.fr/
More information about the R-help
mailing list