[R] Create subset using variable

pansophy mjs2134 at columbia.edu
Sun Jan 22 00:46:38 CET 2012


For example:

# dataset
age<-18:29
height<-58:69
df.ex=data.frame(age=age,height=height)
df.ex[4,1]<-NA

# dataset of columns that will be used for analysis
values<-c("age", "height")
df.variables=data.frame(values)

 # Age column has a null (NA) value.  The row must be removed for the
analysis to run
 # explicit creation  
df.ex.sub.explicit<-subset(df.ex, age >= 0)
dim(df.ex.sub.explicit) #11 obs of 2 variables

i=1
strFilter=as.character(df.variables$values[i])
df.ex.sub.passvar<-subset(df.ex,strFilter>=0)
dim(df.ex.sub.explicit) #12 obs of 2 variables


--
View this message in context: http://r.789695.n4.nabble.com/Create-subset-using-variable-tp4316812p4317196.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list