[R] one row matrix

Marc Schwartz marc_schwartz at comcast.net
Fri Nov 3 23:17:09 CET 2006


On Fri, 2006-11-03 at 14:12 -0800, Waverley wrote:
> Hi,
> 
> when I assign a one row matrix to another variable, then somehow R
> automatically convert that varaible into  a list.

A 'vector', not a 'list'

> For example:
> 
> > a = matrix (12, 3, 4)
> > b = a[1,]
> > b
> [1] 12 12 12 12
> 
> Is there a way to enable R automatically make b as a one row matrix , rather
> than explicitly assign like matrix (b, ncol=1).   I have come across a
> couple of time, that when I try to check how many rows of the computed
> result matrix - nrow(,,,), because there is only one row, the program failed
> as R tried to interpret it as a list.
> 
> Can some one help?

This is actually a FAQ:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-my-matrices-lose-dimensions_003f

HTH,

Marc Schwartz



More information about the R-help mailing list