On 11/3/06, Waverley <[EMAIL PROTECTED]> wrote:
> Hi,
> For example:
>
> > a = matrix (12, 3, 4)
> > b = a[1,]
> > b
> [1] 12 12 12 12
>
It doesn't have anything to do with one-row matrices, at least in your example,
since that isn't what you made. Instead, you created a matrix with 3 rows,
4 columns, and all values equal to 12.
> a <- matrix(12, 3, 4)
> a
[,1] [,2] [,3] [,4]
[1,] 12 12 12 12
[2,] 12 12 12 12
[3,] 12 12 12 12
> a[1,]
[1] 12 12 12 12
You probably intended
> a <- matrix(c(12, 3, 4), nrow=1)
> a
[,1] [,2] [,3]
[1,] 12 3 4
But to solve what I think you were actually asking, even though it
wasn't reflected in your example... By default, R drops unused
dimensions when subsetting. You can override this behavior
> b <- a[1, ,drop=FALSE]
> b
[,1] [,2] [,3]
[1,] 12 3 4
See:
?subset
help('[')
?matrix
Sarah
--
Sarah Goslee
http://www.functionaldiversity.org
______________________________________________
[email protected] 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.