[R] Convert a lis to matrix

Bernardo Rangel Tura tura at centroin.com.br
Sun Jun 7 12:14:04 CEST 2009


On Sun, 2009-06-07 at 00:14 -0400, Manisha Brahmachary wrote:
> Hello,
> 
>  
> 
> This is an urgent request. I want to convert a list of 3 elements into a
> matrix and I am not sure how to do it.
> 
>  
> 
> The list looks like this:
> 
> List of 3
> 
>  $ : num [1:15364, 1] 0.133 0.622 0.588 1.024 0.583 ...
> 
>   ..- attr(*, "dimnames")=List of 2
> 
>   .. ..$ : chr [1:15364] "6420681" "3610072" "2260458" "60689" ...
> 
>   .. ..$ : NULL
> 
>  $ : num [1:15364, 1] 3.159 0.265 0.522 1.912 3.380 ...
> 
>   ..- attr(*, "dimnames")=List of 2
> 
>   .. ..$ : chr [1:15364] "6420681" "3610072" "2260458" "60689" ...
> 
>   .. ..$ : NULL
> 
>  $ : num [1:15364, 1] 3.214 0.277 1.447 1.827 2.054 ...
> 
>   ..- attr(*, "dimnames")=List of 2
> 
>   .. ..$ : chr [1:15364] "6420681" "3610072" "2260458" "60689" ...
> 
>   .. ..$ : NULL

I'm not sure if understood your question, but look this code

a<-list(B=1:3,C=2:4,D=3:5)
matrix(unlist(a),ncol=3)




-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil




More information about the R-help mailing list