[R] NA when indexing vectors

Kenneth Roy Cabrera Torres krcabrer at une.net.co
Fri May 22 03:45:22 CEST 2009


Maybe you mean:

x[which(x>=2)]


El jue, 21-05-2009 a las 14:34 -0400, Jorge Ivan Velez escribió:
> Hi,
> Try:
> 
> which( x>=2 )
> 
> HTH,
> 
> Jorge
> 
> 
> On Thu, May 21, 2009 at 2:28 PM, Szilard <szilard.mailinglists at gmail.com>wrote:
> 
> > Hello:
> >
> > Is there a more natural way to get all elements that satisfy a condition
> > when there are NAs in the sample?
> >
> > > x=c(1,2,NA)
> >
> > > x>=2
> > [1] FALSE  TRUE    NA
> >
> > > x[x>=2]
> > [1]  2 NA         ## I would expect here to get just "2"
> >
> > > x[!is.na(x) & x>=2]   ## seems a bit cumbersome
> > [1] 2
> >
> > Thanks,
> > Szilard
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list