hi all hopefully some one can help. assume that i imported the following data into R (say the data frame is called a) x1 x2 x3 1 NA 3 1 2 NA 1 2 3 3 NA 6 4 5 9 7 5 6 7 8 9 NA 7 9 How can i construct a new data frame that only contains those rows that does not contain the NA's? is these a quick way? ie x1 x2 x3 1 2 3 4 5 9 7 5 6 7 8 9 in this example we can simple use a[c(-1,-2,-4,-8),] but happens if we have a larger dataframe? we need to construct some kind of row indicator telling R which rows contains NA'S. is there an easier method? / allan
R: deleting rows
3 messages · Clark Allan, Dimitris Rizopoulos, Uwe Ligges
look at function ?complete.cases(), e.g., a[complete.cases(a), ] will do the work in your case. I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Clark Allan" <Allan at stats.uct.ac.za> To: <r-help at stat.math.ethz.ch> Cc: "Birgit Erni" <berni at stats.uct.ac.za> Sent: Thursday, September 15, 2005 10:22 AM Subject: [R] R: deleting rows
hi all hopefully some one can help. assume that i imported the following data into R (say the data frame is called a) x1 x2 x3 1 NA 3 1 2 NA 1 2 3 3 NA 6 4 5 9 7 5 6 7 8 9 NA 7 9 How can i construct a new data frame that only contains those rows that does not contain the NA's? is these a quick way? ie x1 x2 x3 1 2 3 4 5 9 7 5 6 7 8 9 in this example we can simple use a[c(-1,-2,-4,-8),] but happens if we have a larger dataframe? we need to construct some kind of row indicator telling R which rows contains NA'S. is there an easier method? / allan
--------------------------------------------------------------------------------
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Clark Allan wrote:
hi all hopefully some one can help. assume that i imported the following data into R (say the data frame is called a) x1 x2 x3 1 NA 3 1 2 NA 1 2 3 3 NA 6 4 5 9 7 5 6 7 8 9 NA 7 9 How can i construct a new data frame that only contains those rows that does not contain the NA's? is these a quick way? ie x1 x2 x3 1 2 3 4 5 9 7 5 6 7 8 9 in this example we can simple use a[c(-1,-2,-4,-8),] but happens if we have a larger dataframe? we need to construct some kind of row indicator telling R which rows contains NA'S. is there an easier method?
na.omit(a) Uwe Ligges
/ allan ------------------------------------------------------------------------
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html