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.
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
Hi, May be try this : data[which(is.na(data[,2])),] 2011/1/25 typhoong <graham.li@eurus-energy.com>> > 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. > > ______________________________________________ > R-help@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. >-- Kamel Gaanoun (+33) (0)6.76.04.65.77 [[alternative HTML version deleted]]
Hi r-help-bounces at r-project.org 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. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
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 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php