Re: [R] how to seperate a matrix
Thanks a lot, Jorge. It works well! On Fri, Dec 4, 2009 at 12:00 AM, Jorge Ivan Velez [via R] ml-node+948277-873392...@n4.nabble.comml-node%2b948277-873392...@n4.nabble.com wrote: Hi aegea, Here is one: m - structure(c(6, 5, 20, 7, 8, 25, 14, 8, 9, 10, 11, 12, 13, 14, 1, 2, 3, 4, 5, 6, 7), .Dim = c(7L, 3L)) m1 - m[m[,1] = m[,2], ] m1 m2 - m[m[,1] m[,2], ] m2 Best, Jorge On Thu, Dec 3, 2009 at 10:12 PM, aegea wrote: 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 lot! My original matrix m is as follows for example, [,1] [,2] [,3] [1,]681 [2,]592 [3,]20 103 [4,]7 114 [5,]8 125 [6,]25 136 [7,] 14 147 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,]681 [2,]592 [3,]7 114 [4,]8 125 m2 supposed to be like: [,1] [,2] [,3] [1,]20 103 [2,]25 136 [3,] 14 147 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. __ [hidden email]http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=948277i=0mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ [hidden email]http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=948277i=1mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View message @ http://n4.nabble.com/how-to-seperate-a-matrix-tp948225p948277.html To unsubscribe from how to seperate a matrix, click here (link removed) ==. -- Best, Chen -- View this message in context: http://n4.nabble.com/how-to-seperate-a-matrix-tp948225p948859.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to seperate a matrix
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 lot! My original matrix m is as follows for example, [,1] [,2] [,3] [1,]681 [2,]592 [3,]20 103 [4,]7 114 [5,]8 125 [6,]25 136 [7,] 14 147 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,]681 [2,]592 [3,]7 114 [4,]8 125 m2 supposed to be like: [,1] [,2] [,3] [1,]20 103 [2,]25 136 [3,] 14 147 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to seperate a matrix
Hi there, mymat-matrix(c(6,8,1, 5,9,2, 20,10,3, 7,11,4, 8,12,5, 25,13,6, 14,14,7), byrow=T, ncol=3) mymat1-mymat[mymat[,1]mymat[,2],] mymat1 mymat2-mymat[mymat[,1]=mymat[,2],] mymat2 bests milton On Thu, Dec 3, 2009 at 10:12 PM, aegea gche...@gmail.com wrote: 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 lot! My original matrix m is as follows for example, [,1] [,2] [,3] [1,]681 [2,]592 [3,]20 103 [4,]7 114 [5,]8 125 [6,]25 136 [7,] 14 147 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,]681 [2,]592 [3,]7 114 [4,]8 125 m2 supposed to be like: [,1] [,2] [,3] [1,]20 103 [2,]25 136 [3,] 14 147 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to seperate a matrix
Hi aegea, Here is one: m - structure(c(6, 5, 20, 7, 8, 25, 14, 8, 9, 10, 11, 12, 13, 14, 1, 2, 3, 4, 5, 6, 7), .Dim = c(7L, 3L)) m1 - m[m[,1] = m[,2], ] m1 m2 - m[m[,1] m[,2], ] m2 Best, Jorge On Thu, Dec 3, 2009 at 10:12 PM, aegea wrote: 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 lot! My original matrix m is as follows for example, [,1] [,2] [,3] [1,]681 [2,]592 [3,]20 103 [4,]7 114 [5,]8 125 [6,]25 136 [7,] 14 147 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,]681 [2,]592 [3,]7 114 [4,]8 125 m2 supposed to be like: [,1] [,2] [,3] [1,]20 103 [2,]25 136 [3,] 14 147 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.