I have dataset df
df<-data.frame(outcome=sample(c(0,1),100,T),
v1=rnorm(100,10,2),
v2=rnorm(100,10,2),
v3=rnorm(100,10,2),
v4=rnorm(100,10,2),
v5=rnorm(100,10,2))
And I make a list of variables I want to look at in a later model:
list<-c("v1","v3","v5")
And I want to be able to manipulate list in order to enter it into a glm model:
magical steps
.
.
.
To give the desired formula call:
glm(outcome~v1+v3+v5,data=df,family="binomial")
Where glm(outcome~ and ,data=df,family="binomial") are preset, but v1+v3+v5 is the result of manipulations on list.
When my list is only a length of 1, I can get away with ~ df[,list], but when length(list) > 1 I get:
ERROR: R: invalid type (list) for variable 'df[, list]'
I've also tried creating a smaller dataset:
predictors<-df[,list]
and entering that in:
glm(outcome~predictors,data=df,family="binomial")
but I get a similar error:
ERROR: R: invalid type (list) for variable 'predictors'
Thank you!