[R] Partitioning matrix
Let say, I have following matrix : dat - matrix(rnorm(40), 2, 20) Now I want to partition this like this : dat1 - dat[1,] dat2 - dat[2,] But point is that, dat1 and dat2 become vector object. How can I force them to be matrix object with dimension (1x20) ? Thanks, -- View this message in context: http://www.nabble.com/Partitioning-matrix-tp24161021p24161021.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] Partitioning matrix
Bogaso wrote: Let say, I have following matrix : dat - matrix(rnorm(40), 2, 20) Now I want to partition this like this : dat1 - dat[1,] dat2 - dat[2,] But point is that, dat1 and dat2 become vector object. How can I force them to be matrix object with dimension (1x20) ? To turn a vector into a matrix or array set it's dimension attribute like so: dim(dat1) - c(1,20) dim(dat2) - c(1,20) Hope that helps! -Charlie - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://www.nabble.com/Partitioning-matrix-tp24161021p24161038.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] Partitioning matrix
see ?[ and notice the 'drop' argument. So in your example try dat[1, , drop=FALSE] hth, Kingsford On Tue, Jun 23, 2009 at 1:13 AM, Bogasobogaso.christo...@gmail.com wrote: Let say, I have following matrix : dat - matrix(rnorm(40), 2, 20) Now I want to partition this like this : dat1 - dat[1,] dat2 - dat[2,] But point is that, dat1 and dat2 become vector object. How can I force them to be matrix object with dimension (1x20) ? Thanks, -- View this message in context: http://www.nabble.com/Partitioning-matrix-tp24161021p24161021.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. __ 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.