[R] subsetting with NA's

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Apr 8 13:08:24 CEST 2002


"David Kane  <David Kane" <a296180 at mica.fmr.com> writes:

> My problem is that this sort of syntax can become quite annoying when their are
> many variables in the subseting expression. That is, I want to writing
> something like:
> 
> x[x$b < 3 & x$c > 5 & x$d > 100,]
> 
> without having to write:
> 
> x[! is.na(x$b) & ! is.na(x$c) & ! is.na(x$d) & x$b < 3 & x$c > 5 & x$d > 100,]
> 
> Is there a trick for achieving this, for ignoring all NA's during subsetting?

subset(x, b < 3 & c > 5 & d > 100) exists for that very reason...

-- 
   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