[R] Excluding rows from a matrix - best option
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue Aug 22 11:52:40 CEST 2000
José Ernesto Jardim <ernesto at ipimar.pt> writes:
> José Ernesto Jardim wrote:
>
> > Hi
> >
> > I have a matrix (4 x 950) and I want to remove 3 rows, where the values
> > from the first column are 713, 714 and 715. I can select the rows, one
> > by one, with
> >
> > mat[mat$first==713,]
> > mat[mat$first==714,]
....
> The best way I found after these messages and with your help was
>
> (i) selecting diferent rows
>
> mat[(mat$first==c(###, ###, ...)),]
>
> (ii) excluding diferent rows
>
> mat[!(mat$first==c(###, ###, ...)),]
Whoa! I don't think that actually works:
> first<-1:6
> first==1:3
[1] TRUE TRUE TRUE FALSE FALSE FALSE
> first==2:4
[1] FALSE FALSE FALSE FALSE FALSE FALSE
You really need the %in% operator:
> first %in% 2:4
[1] FALSE TRUE TRUE TRUE FALSE FALSE
Also, btw: subset(mat, first %in% c(713,714,715)) resp.
subset(mat, !(first %in% c(713,714,715)))
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list