Daniel Tucker
2013-Jun-05 13:33 UTC
[R] Subsetting out missing values for a certain variable
I am trying to create a new datafarme using the subset function given 2 conditions subset1<- subset(dframe, glb_ind="Y" | sample==1) subset2<-subset(dframe, cwar_ind="Y" | sample==2) subset3<-subset(dframe, reg_ind="Y" | sample==3) However, my first conditions (glb_ind,cwar_ind, and reg_ind) all have missing values (they are either Y, N, or no value. In subsetting my data, I am looking to not only get rid of the "N" in the new dataframes, but also the NA's. I don't want to na.omit the entire data frame; I only want to get rid of missing values (and non Y values) for a certain variable (glb_ind, cwar_ind, reg_ind) for each subset. Is there anyway I can do this? Thanks, Dan [[alternative HTML version deleted]]
Daniel Tucker
2013-Jun-05 13:54 UTC
[R] Subsetting out missing values for a certain variable
Also tried this but results werent any different subset1<- subset(dframe, glb_ind="Y" | sample==1 | !is.na(glb_ind)) subset2<-subset(dframe, cwar_ind="Y" |sample==2 | !is.na(cwar_ind)) subset3<-subset(dframe, reg_ind="Y" | sample==3 | !is.na(reg_ind)) On Wed, Jun 5, 2013 at 9:33 AM, Daniel Tucker <daniel.tucker@rochester.edu>wrote:> I am trying to create a new datafarme using the subset function given 2 > conditions > > subset1<- subset(dframe, glb_ind="Y" | sample==1) > subset2<-subset(dframe, cwar_ind="Y" | sample==2) > subset3<-subset(dframe, reg_ind="Y" | sample==3) > > However, my first conditions (glb_ind,cwar_ind, and reg_ind) all have > missing values (they are either Y, N, or no value. In subsetting my data, I > am looking to not only get rid of the "N" in the new dataframes, but also > the NA's. I don't want to na.omit the entire data frame; I only want to get > rid of missing values (and non Y values) for a certain variable (glb_ind, > cwar_ind, reg_ind) for each subset. Is there anyway I can do this? > > Thanks, > Dan > > >[[alternative HTML version deleted]]