[R] logical subsetting, indexes and NAs

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Sat Jan 28 21:45:51 CET 2012


how about

x[x < 10 & !is.na(x)]


I hope it helps.

Best,
Dimitris


On 1/28/2012 9:36 PM, Federico Calboli 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.
>

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/



More information about the R-help mailing list