Re: [R] Converting a list to a matrix - I still don't think I have it right

2005-02-17 Thread Sean Davis
Mick,
Does this do it?
mymat - do.call('rbind',l2)
rownames(mymat) - names(l2)
Sean
On Feb 17, 2005, at 9:36 AM, michael watson ((IAH-C)) wrote:
Hi
We have touched on this before, but I don't think I quite got it right.
So I have a list, each element of which is a a vector of 2 numbers:
l2
$cat000_a01
[1] 0.3429944 4.5138244
$cat000_a02
[1] 0.1929336 4.3064944
$cat000_a03
[1] -0.2607796  4.1551591
What I actually want to convert this into is a matrix with the names
(cat000_a01 etc) as row names, the first element of each of the vectors
forming the first column of the new matrix, and the second element of
each of the vectors forming the second column:
cat000_a01  0.3429944   4.5138244
cat000_a02  0.1929336   4.3064944
cat000_a03  -0.2607796  4.1551591
What was suggested on the list last time was
matrix(unlist(mylist),nrow=length(mylist)).  But if I do this I get:
matrix(unlist(l2),nrow=length(l2))
  [,1]   [,2]
[1,] 0.3429944  4.3064944
[2,] 4.5138244 -0.2607796
[3,] 0.1929336  4.1551591
Which is not what I want.  Here, the second element of the first vector
in my list has gone into the first column of the new matrix, and that's
not what I want at all.
Any more help would be appreciated.
Thanks
Mick
__
R-help@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
__
R-help@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


Re: [R] Converting a list to a matrix - I still don't think I have it right

2005-02-17 Thread Roger D. Peng
Does
do.call(rbind, l2)
do what you want?
-roger
michael watson (IAH-C) wrote:
Hi
We have touched on this before, but I don't think I quite got it right.
So I have a list, each element of which is a a vector of 2 numbers:

l2
$cat000_a01
[1] 0.3429944 4.5138244
$cat000_a02
[1] 0.1929336 4.3064944
$cat000_a03
[1] -0.2607796  4.1551591
What I actually want to convert this into is a matrix with the names
(cat000_a01 etc) as row names, the first element of each of the vectors
forming the first column of the new matrix, and the second element of
each of the vectors forming the second column:
cat000_a01  0.3429944   4.5138244
cat000_a02  0.1929336   4.3064944
cat000_a03  -0.2607796  4.1551591
What was suggested on the list last time was
matrix(unlist(mylist),nrow=length(mylist)).  But if I do this I get:

matrix(unlist(l2),nrow=length(l2))
  [,1]   [,2]
[1,] 0.3429944  4.3064944
[2,] 4.5138244 -0.2607796
[3,] 0.1929336  4.1551591
Which is not what I want.  Here, the second element of the first vector
in my list has gone into the first column of the new matrix, and that's
not what I want at all.
Any more help would be appreciated.
Thanks
Mick
__
R-help@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
--
Roger D. Peng
http://www.biostat.jhsph.edu/~rpeng/
__
R-help@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


Re: [R] Converting a list to a matrix - I still don't think I have it right

2005-02-17 Thread Petr Pikal
Hi Michael

On 17 Feb 2005 at 14:36, michael watson (IAH-C) wrote:

 Hi
 
 We have touched on this before, but I don't think I quite got it
 right.
 
 So I have a list, each element of which is a a vector of 2 numbers:
 
  l2
 $cat000_a01
 [1] 0.3429944 4.5138244
 
 $cat000_a02
 [1] 0.1929336 4.3064944
 
 $cat000_a03
 [1] -0.2607796  4.1551591
 
 What I actually want to convert this into is a matrix with the names
 (cat000_a01 etc) as row names, the first element of each of the
 vectors forming the first column of the new matrix, and the second
 element of each of the vectors forming the second column:
 
 cat000_a010.3429944   4.5138244
 cat000_a020.1929336   4.3064944
 cat000_a03-0.2607796  4.1551591
 
 What was suggested on the list last time was
 matrix(unlist(mylist),nrow=length(mylist)).  But if I do this I get:
 
  matrix(unlist(l2),nrow=length(l2))
   [,1]   [,2]
 [1,] 0.3429944  4.3064944
 [2,] 4.5138244 -0.2607796
 [3,] 0.1929336  4.1551591

Try byrow =TRUE argument

 x-list(a=c(1,2), b=c(4,5), d= c(10,12))

 matrix(unlist(x),nrow=length(x), byrow=T)
 [,1] [,2]
[1,]12
[2,]45
[3,]   10   12


Cheers 
Petr




 Which is not what I want.  Here, the second element of the first
 vector in my list has gone into the first column of the new matrix,
 and that's not what I want at all.
 
 Any more help would be appreciated.
 
 Thanks
 Mick
 
 __
 R-help@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

Petr Pikal
[EMAIL PROTECTED]

__
R-help@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


Re: [R] Converting a list to a matrix - I still don't think I have it right

2005-02-17 Thread Peter Dalgaard
michael watson (IAH-C) [EMAIL PROTECTED] writes:

 Hi
 
 We have touched on this before, but I don't think I quite got it right.
 
 So I have a list, each element of which is a a vector of 2 numbers:
 
  l2
 $cat000_a01
 [1] 0.3429944 4.5138244
 
 $cat000_a02
 [1] 0.1929336 4.3064944
 
 $cat000_a03
 [1] -0.2607796  4.1551591
 
 What I actually want to convert this into is a matrix with the names
 (cat000_a01 etc) as row names, the first element of each of the vectors
 forming the first column of the new matrix, and the second element of
 each of the vectors forming the second column:
 
 cat000_a010.3429944   4.5138244
 cat000_a020.1929336   4.3064944
 cat000_a03-0.2607796  4.1551591

do.call(rbind, list)

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
R-help@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