[R] getting variable names into formulas

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Sep 9 18:56:38 CEST 2002



"J.R. Lockwood" wrote:
> 
> Hello,
> 
> I have a dataframe with several hundred variables.  I would like to
> explore updates of some baseline lme fit by including each of some
> subset of these variables, one at a time.  For various reasons it is
> inconvenient to rely on the positions of the numbered columns in the
> dataframe.  Here is what I want to do:
> 
> mod.baseline<-lme(fixed=foo,data=dat,random=bar)
> for(thisvar in vars){
>   <collect stuff from update(mod.baseline, ~ . ~ + thisvar)>
> }
> 
> I have tried defining "vars" to be a vector of character strings
> giving the names of the variables I want to use, and then using
> "as.name(thisvar)" in the formula argument to update().  This doesn't
> work (and might be embarrasingly naive).  What does seem to work is
> 
> "update(mod.baseline,. ~ . + dat[,which(names(dat)==thisvar)])"
> 
> but is not elegant and of only limited use because of the lack of
> association with the variable name.
> 
> My question is whether there is a better way to do this, either with
> "vars" as defined above or through some more clever definition.
> 
> Thanks to all for your consideration.

You are looking for get().

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list