Why does R need the concept of "Vector"? In my opinion, it is a useless and confusing concept. A vector is simply a special case of a matrix whose row or column number is equal to 1. When I take submatrix from one matrix and if row or column number is 1, R will automatically convert it into a vector. It is very straightforward that a submatrix of a matrix should be a matrix. In each time, I have to use as.matrix() to convert the vector back to matrix. It is very annoying! -- View this message in context: http://n4.nabble.com/Confusing-concept-of-vector-and-matrix-in-R-tp1707170p1707170.html Sent from the R help mailing list archive at Nabble.com.
On 30/03/2010, at 12:13 PM, yehengxin wrote:> > Why does R need the concept of "Vector"? In my opinion, it is a useless and > confusing concept. A vector is simply a special case of a matrix whose row > or column number is equal to 1. When I take submatrix from one matrix and > if row or column number is 1, R will automatically convert it into a vector. > It is very straightforward that a submatrix of a matrix should be a matrix. > In each time, I have to use as.matrix() to convert the vector back to > matrix. It is very annoying!Well then, why don't you go away and design and build your own statistics and data analysis language/package to replace R? You can then make whatever design decisions you like, and you won't have to live with the design decisions made by such silly and inept people as John Chambers and Rick Becker and their ilk. cheers, Rolf Turner ###################################################################### Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.com ######################################################################
yehengxin wrote:> > Why does R need the concept of "Vector"? In my opinion, it is a useless > and confusing concept. A vector is simply a special case of a matrix > whose row or column number is equal to 1. When I take submatrix from one > matrix and if row or column number is 1, R will automatically convert it > into a vector. It is very straightforward that a submatrix of a matrix > should be a matrix. In each time, I have to use as.matrix() to convert > the vector back to matrix. It is very annoying! >Except that to a computer all "matricies" and "arrays" are just vectors for which some human arbitrarily declared something like "row break every n entries". And R can be told not to perform the conversion from sub-matrix to vector, open the help page for the subset operator: ?"[" And play with the drop option. -Charlie ----- Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Confusing-concept-of-vector-and-matrix-in-R-tp1707170p1735190.html Sent from the R help mailing list archive at Nabble.com.
> Why does R need the concept of "Vector"? ?In my opinion, it is a useless and > confusing concept. ?A vector is simply a special case of a matrix whose row > or column number is equal to 1. ?When I take submatrix from one matrix and > if row or column number is 1, R will automatically convert it into a vector. > It is very straightforward that a submatrix of a matrix should be a matrix. > In each time, I have to use as.matrix() to convert the vector back to > matrix. ? ?It is very annoying!Good thing there's a way to get around this then: R> m <- matrix(1:20, 4, 5) R> m [,1] [,2] [,3] [,4] [,5] [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20 R> m[,1] [1] 1 2 3 4 R> m[,1,drop=FALSE] [,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 R> is.matrix(m[,1,drop=FALSE]) [1] TRUE -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
Actually R looks at it the other way around. It regards a matrix as a special case of a vector. A vector has no dimensions. A vector with dimensions is an array. An array with two dimensions is a matrix. Try using drop=FALSE like this: m <- matrix(1:6, 3) m[, 2, drop = FALSE] On Mon, Mar 29, 2010 at 7:13 PM, yehengxin <xye78 at hotmail.com> wrote:> > Why does R need the concept of "Vector"? ?In my opinion, it is a useless and > confusing concept. ?A vector is simply a special case of a matrix whose row > or column number is equal to 1. ?When I take submatrix from one matrix and > if row or column number is 1, R will automatically convert it into a vector. > It is very straightforward that a submatrix of a matrix should be a matrix. > In each time, I have to use as.matrix() to convert the vector back to > matrix. ? ?It is very annoying! > -- > View this message in context: http://n4.nabble.com/Confusing-concept-of-vector-and-matrix-in-R-tp1707170p1707170.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >