Extract NA data rows

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Extract NA data rows

typhoong
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





Reply | Threaded
Open this post in threaded view
|

Re: Extract NA data rows

David Scott-6
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: [hidden email],  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Extract NA data rows

kamel gaanoun
In reply to this post by typhoong
Hi,

May be try this :

data[which(is.na(data[,2])),]

2011/1/25 typhoong <[hidden email]>

>
> 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
>
>
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Extract-NA-data-rows-tp3235568p3235568.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>



--
Kamel Gaanoun
(+33) (0)6.76.04.65.77

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Odp: Extract NA data rows

PIKAL Petr
In reply to this post by typhoong
Hi

[hidden email] napsal dne 25.01.2011 08:07:10:

>
> 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")

See

?is.na

however ?complete.cases is my preferred choice when working with data
frames and several columns.

dataframe[complete.cases(dataframe),]

Regards
Petr

>
> but fail. if you know the answers, please let me know thanks.
>
> typhoong
>
>
>
>
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Extract-NA-data-
> rows-tp3235568p3235568.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Extract NA data rows

Ivan Calandra
In reply to this post by typhoong
Hi!

Try
subset(dataframe, is.na(y))

or
df[is.na(df$y),]

HTH,
Ivan

Le 1/25/2011 08:07, typhoong a écrit :

> 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
>
>
>
>
>
>

--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
[hidden email]

**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Extract NA data rows

typhoong
big thanks for all answers !