[R] how to seperate a matrix

aegea gcheer3 at gmail.com
Fri Dec 4 04:12:44 CET 2009


Hello,

I am working on seperate the matrix to two matrices but got trouble on doing
it. Please give me some suggestions on doing this. Thanks a looooooooooooot!

My original matrix m is as follows for example,

     [,1] [,2] [,3]
[1,]    6    8    1
[2,]    5    9    2
[3,]    20  10    3
[4,]    7   11    4
[5,]    8   12    5
[6,]    25   13    6
[7,]   14   14    7

I want to generate two matrix m1 and m2
if m[i, 1] <m[i,2], then the row is stored in new matrix m1, (i =1, ..., 7)
if m[i,1]>=m[i,2], then the row is stored in new matrix m2.

m1 supposed to be like: 
     [,1] [,2] [,3]
[1,]    6    8    1
[2,]    5    9    2
[3,]    7   11    4
[4,]    8   12    5

m2 supposed to be like:
     [,1] [,2] [,3]
[1,]    20  10    3
[2,]    25   13    6
[3,]   14   14    7


How can I code the if statement? Thank you very much

-- 
View this message in context: http://n4.nabble.com/how-to-seperate-a-matrix-tp948225p948225.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list