[R] matrix selection return types

vincent at 7d4.com vincent at 7d4.com
Thu Jun 15 15:41:14 CEST 2006


Dear Rusers,

I would like some comments about the following results
(under R-2.2.0)

 > m = matrix(1:6 , 2 , 3)
 > m
      [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

 > z1 = m[(m[,1]==2),]
 > z1
[1] 2 4 6
 > is.matrix(z1)
[1] FALSE

 > z2 = m[(m[,1]==0),]
 > z2
      [,1] [,2] [,3]
 > is.matrix(z2)
[1] TRUE

Considered together, I'm a bit surprised about the
returned types from z1 and z2.
I would not have been surprised if z1 would still
have been a matrix, or z2=NULL.

There is certainly a logic behind this choice
but it's not very clear for me,
so any help/comment appreciated.

Thanks
Vincent



More information about the R-help mailing list