Possible Duplicate:
Formula with dynamic number of variables
I'm fitting a linear model with many variables and would like to automatically generate a dynamic string following the form of the lm() function in R ("Y ~ X1 + ... + Xn"). The idea is to plug-in the string into the lm() formula so don't have to write down all the names manually.
Also I would like set the name of the response variable so it's identified and included in the first place of the string (" Y ~ ...")
Is this possible? I'm playing with the "state.x77" data set. Let's say I want to use as a response the "Life Exp" variable.
state.x77
str(state.x77)
st = as.data.frame(state.x77)
n=ncol(st)