Hello, I have many hundred variables in my longitudinal dataset and lots of missings. In order to plot data I need to remove missings. If I do> data <- na.omit(data)that will reduce my dataset to 2% of its original size ;) So I only need to listwise delete missings on 3 variables (the ones I am plotting). data$variable1 <-na.omit(data$variable1) does not work. Thank you [[alternative HTML version deleted]]
On Jul 5, 2012, at 1:25 PM, Eiko Fried wrote:> Hello, > > I have many hundred variables in my longitudinal dataset and lots of > missings. In order to plot data I need to remove missings. > > If I do >> data <- na.omit(data) > that will reduce my dataset to 2% of its original size ;) > > So I only need to listwise delete missings on 3 variables (the ones > I am > plotting). > > data$variable1 <-na.omit(data$variable1)?complete.cases # returns a logical vector data[ complete.cases( data[ , c("var1", "var2", "var3"]) , ] David Winsemius, MD West Hartford, CT
HI,
Try this:
set.seed(1)
dat1<-data.frame(var1=c(rep(NA,3),1:3),var2=c(1:4,NA,5),var3=c(1:5,NA),var4=rnorm(6,15),var5=runif(6,0.2),var6=rep(NA,6))
?dat1[rowSums(is.na(dat1[,c("var1","var2","var3")]))==0,]
?var1 var2 var3???? var4????? var5 var6
4??? 1??? 4??? 4 16.59528 0.5981594?? NA
A.K.
----- Original Message -----
From: Eiko Fried <torvon at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Thursday, July 5, 2012 1:25 PM
Subject: [R] Exclude missing values on only 1 variable
Hello,
I have many hundred variables in my longitudinal dataset and lots of
missings. In order to plot data I need to remove missings.
If I do> data <- na.omit(data)
that will reduce my dataset to 2% of its original size ;)
So I only need to listwise delete missings on 3 variables (the ones I am
plotting).
data$variable1 <-na.omit(data$variable1)
does not work.
Thank you
??? [[alternative HTML version deleted]]
______________________________________________
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,Try this:
HI,
Try this:
set.seed(1)
dat1<-data.frame(var1=c(rep(NA,3),1:3),var2=c(1:4,NA,5),var3=c(1:5,NA),var4=rnorm(6,15),var5=runif(6,0.2),var6=rep(NA,6))
?dat1[rowSums(is.na(dat1[,c("var1","var2","var3")]))==0,]
?var1 var2 var3???? var4????? var5 var6
4??? 1??? 4??? 4 16.59528 0.5981594?? NA
A.K.
----- Original Message -----
From: Eiko Fried <torvon at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Thursday, July 5, 2012 1:25 PM
Subject: [R] Exclude missing values on only 1 variable
Hello,
I have many hundred variables in my longitudinal dataset and lots of
missings. In order to plot data I need to remove missings.
If I do> data <- na.omit(data)
that will reduce my dataset to 2% of its original size ;)
So I only need to listwise delete missings on 3 variables (the ones I am
plotting).
data$variable1 <-na.omit(data$variable1)
does not work.
Thank you
??? [[alternative HTML version deleted]]
______________________________________________
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,Try this:
On Jul 5, 2012, at 1:34 PM, David Winsemius wrote:> > On Jul 5, 2012, at 1:25 PM, Eiko Fried wrote: > >> Hello, >> >> I have many hundred variables in my longitudinal dataset and lots of >> missings. In order to plot data I need to remove missings. >> >> If I do >>> data <- na.omit(data) >> that will reduce my dataset to 2% of its original size ;) >> >> So I only need to listwise delete missings on 3 variables (the ones >> I am >> plotting). >> >> data$variable1 <-na.omit(data$variable1) > > ?complete.cases # returns a logical vector > > data[ complete.cases( data[ , c("var1", "var2", "var3"]) , ] > > data[ complete.cases( data[ , c("var1", "var2", "var3") ] ) , ]Er, need to add a right - paren -----here -----------^>-- David Winsemius, MD West Hartford, CT