[R] logical subsetting, indexes and NAs

baptiste auguie baptiste.auguie at googlemail.com
Sat Jan 28 21:45:43 CET 2012


Hi,

which(x < 15)

omits the NA (treated as false).

HTH,

b.

On 29 January 2012 09:36, Federico Calboli <f.calboli at imperial.ac.uk> wrote:
> Dear All,
>
> just a quick example:
>
>
>> x  = 1:25
>> x[12] = NA
>
>> x
>  [1] 1 2 3 4 5 6 7 8 9 10 11 NA 13 14 15 16 17 18 19 20 21 22 23 24 25
>
>> y = x[x<10]
>> y
>  [1]  1  2  3  4  5  6  7  8  9 NA
>
> Is there any way of NOT getting NA for y = x[x<10]? Similarly
>
>> y = x[x<15]
>> y
>  [1] 1 2 3 4 5 6 7 8 9 10 11 NA 13 14
>
>
> How do I get rid of the NA (not post hoc)?
>
> BW
>
> F
>
>
>
> --
> Federico C. F. Calboli
> Neuroepidemiology and Ageing Research
> Imperial College, St. Mary's Campus
> Norfolk Place, London W2 1PG
>
> Tel +44 (0)20 75941602   Fax +44 (0)20 75943193
>
> f.calboli [.a.t] imperial.ac.uk
> f.calboli [.a.t] gmail.com
>
> ______________________________________________
> 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