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
Hi On 15 Jun 2006 at 15:41, vincent at 7d4.com wrote: Date sent: Thu, 15 Jun 2006 15:41:14 +0200 From: vincent at 7d4.com To: r-help at stat.math.ethz.ch Subject: [R] matrix selection return types> 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.If you want z1 to be matrix see argument drop in ?"[" z1 = m[(m[,1]==2),,drop=F] however why matrix is retained in second case i am not sure. Probably only if the result has exactly one dimension it is stripped from dim attribute by default. HTH Petr> > There is certainly a logic behind this choice > but it's not very clear for me, > so any help/comment appreciated. > > Thanks > Vincent > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
> m = matrix(1:6 , 2 , 3) > ?'[' > z1 <- m[m[,1] == 2,] > z1[1] 2 4 6> is.matrix(z1)[1] FALSE> z1 <- m[m[,1] == 2,, drop=FALSE] > z1[,1] [,2] [,3] [1,] 2 4 6> is.matrix(z1)[1] TRUE>On 6/15/06, vincent@7d4.com <vincent@7d4.com> wrote:> > 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 > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >-- Jim Holtman Cincinnati, OH +1 513 646 9390 (Cell) +1 513 247 0281 (Home) What is the problem you are trying to solve? [[alternative HTML version deleted]]
jim holtman a ?crit :> > z1 <- m[m[,1] == 2,, drop=FALSE] > What is the problem you are trying to solve?It was not really a big problem. Just that without the "drop" argument, The changing returned type complicated the next computations. drop=TRUE makes it homogeneous, which is what I needed. Thanks for your answer.