[R] evaluate NA to FALSE instead of NA?

Rainer M Krug Rainer at krugs.de
Tue Oct 14 11:51:17 CEST 2014


Hi

I want to evaluate NA and NaN to FALSE (for indexing) so I would like to
have the result as indicated here:

,----
| > p <- c(1:10/100, NA, NaN)
| > p
|  [1] 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10   NA  NaN
| > p[p<=0.05]
| [1] 0.01 0.02 0.03 0.04 0.05   NA   NA
| > p[sapply(p<=0.05, isTRUE)]
| [1] 0.01 0.02 0.03 0.04 0.05  <<<=== I want this
`----

Is there a way that I can do this more easily then in my example above?
It works, but it strikes me that there is not a better way of doing
this - am I missing a command or option?

Thanks,

Rainer

-- 
Rainer M. Krug
email: Rainer<at>krugs<dot>de
PGP: 0x0F52F982
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 494 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20141014/832c205b/attachment.bin>


More information about the R-help mailing list