[R] Subsetting a matrix [Again!]
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Tue Jul 15 12:14:05 CEST 2003
Hi Folks,
People's suggestion of "drop=FALSE" seemed to do the trick
(preserving "matrix" character when subestting to a row,
i.e. creating 1xk matrix).
However, I seem to have encountered a case where even this does
not work:
> mu<-c(1,2,3)
> mu<-matrix(mu,nrow=1)
> mu
[,1] [,2] [,3]
[1,] 1 2 3
> iX1<-c(T,F,F); iX2<- !iX1
> mu1<-mu[iX1,drop=FALSE]; mu2<-mu[iX2,drop=FALSE];
> mu1
[1] 1
> mu2
[1] 2 3
So now I still don't get my 1xk matrices, even though mu is a
matrix and I've used "drop=FALSE". Why?
(I'm getting a bit bewildered by all this, and must get it pinned
down: the code this will go into is too complicated to allow easy
debugging if the subsetting does unpredicted things.)
[BTW: Just in case anyone gets the thought that it might work if you
matrify iX1, iX2 e.g. iX1<-matrix(iX1,nrow=1) -- well, it doesn't!]
Best wishes to all,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 15-Jul-03 Time: 11:14:05
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list