Hello, I have a variable in a data frame that contains NA values. I just want to subset so that I get the obs where that variable is missing. In SAS I would do: data missing; set test; if myvalue=' '; run; How can I perform this simple task in R? Thanks in advance for your help. -- View this message in context: http://r.789695.n4.nabble.com/subset-data-frame-by-variable-with-missing-value-tp4651439.html Sent from the R help mailing list archive at Nabble.com.
subset data frame by variable with missing value
6 messages · ramoss, Marc Schwartz, PIKAL Petr +2 more
I found the answer; Its mymissing <- subset(mydata,is.na(myvar)) -- View this message in context: http://r.789695.n4.nabble.com/subset-data-frame-by-variable-with-missing-value-tp4651439p4651440.html Sent from the R help mailing list archive at Nabble.com.
On Nov 30, 2012, at 9:27 AM, ramoss <ramine.mossadegh at finra.org> wrote:
Hello, I have a variable in a data frame that contains NA values. I just want to subset so that I get the obs where that variable is missing. In SAS I would do: data missing; set test; if myvalue=' '; run; How can I perform this simple task in R? Thanks in advance for your help.
The easiest is probably: NewDF <- subset(DF, is.na(myvalue)) See ?is.na Regards, Marc Schwartz
Hi see ?is.na x <-sample(c(1:3, NA), 20, replace=T) x [1] 2 NA 2 3 3 3 3 2 3 NA 3 2 1 2 NA 3 3 3 2 2 y<-rnorm(20) y[is.na(x)] [1] 0.1600417 1.3264063 -0.6175832 Regards Petr
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of ramoss Sent: Friday, November 30, 2012 4:27 PM To: r-help at r-project.org Subject: [R] subset data frame by variable with missing value Hello, I have a variable in a data frame that contains NA values. I just want to subset so that I get the obs where that variable is missing. In SAS I would do: data missing; set test; if myvalue=' '; run; How can I perform this simple task in R? Thanks in advance for your help. -- View this message in context: http://r.789695.n4.nabble.com/subset- data-frame-by-variable-with-missing-value-tp4651439.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 guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code.
Le vendredi 30 novembre 2012 ? 07:27 -0800, ramoss a ?crit :
Hello, I have a variable in a data frame that contains NA values. I just want to subset so that I get the obs where that variable is missing. In SAS I would do: data missing; set test; if myvalue=' '; run; How can I perform this simple task in R?
missing <- test[is.na(test$myvalue),] or missing <- subset(test, is.na(myvalue)) Regards
Thanks in advance for your help. -- View this message in context: http://r.789695.n4.nabble.com/subset-data-frame-by-variable-with-missing-value-tp4651439.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 guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hi, YOu could also use: set.seed(5) dat1<-data.frame(col1=sample(c(1:4,NA),10,replace=TRUE),col2=runif(10,0,1)) ?dat1[!complete.cases(dat1),] #? col1????? col2 #3?? NA 0.3184040 #8?? NA 0.8878698 #9?? NA 0.5549226 A.K. ----- Original Message ----- From: ramoss <ramine.mossadegh at finra.org> To: r-help at r-project.org Cc: Sent: Friday, November 30, 2012 10:27 AM Subject: [R] subset data frame by variable with missing value Hello, I have a variable in a data frame that contains NA values. I just want to subset so that I get the obs where that variable is missing. In SAS I would do: data missing; ? set test; ? if myvalue=' '; run; How can I perform this simple task in R? Thanks in advance for your help. -- View this message in context: http://r.789695.n4.nabble.com/subset-data-frame-by-variable-with-missing-value-tp4651439.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 guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.