[R] Extract NA data rows
David Scott
d.scott at auckland.ac.nz
Tue Jan 25 09:34:21 CET 2011
On 25/01/2011 8:07 p.m., typhoong wrote:
>
> hi i have the following dataframe
>
> x y
> 1 345
> 6 NA
> 8 123
> 32 123
> 12 NA
> 6 124
> 7 NA
>
> and i want to extract the data rows which contains "NA" data, I tried
>
> subset(dataframe,y=="NA")
>
> but fail. if you know the answers, please let me know thanks.
>
> typhoong
>
Your test is wrong for NA. You must use is.na:
> df
x y
1 1 345
2 6 NA
3 8 123
4 32 123
5 12 NA
6 6 124
7 7 NA
> subset(df, is.na(y))
x y
2 6 NA
5 12 NA
7 7 NA
--
_________________________________________________________________
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142, NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email: d.scott at auckland.ac.nz, Fax: +64 9 373 7018
Director of Consulting, Department of Statistics
More information about the R-help
mailing list