[R] converting a string to an element in a function call

Adrian Vance Custer acuster at nopause.berkeley.edu
Wed Jun 21 21:10:41 CEST 2000


Hello everyone,

I'm trying to write a function that will step through a vector of strings and
evaluate the contribution to the R-squared of each in turn. I suspect this is
related to the anova(model) call but not quite sure how and anova() is order
dependent so I have to step through orders anyhow.

The issue is that I pass a vector of strings to the function and want to use it
as:

update(.~.+ do.something.to.the.string(vector.argument.of.strings[i])
or in the code below
update(.~.+unknown(facvec[i]))

I've tried a whole bunch of things I don't understand parse(),as.expession()
and the as.name() below but none seem to work.



Here is the function I am using:

function(facvec,base.lm){
if ( missing(facvec) || missing(base.lm) ){
  cat("This script assesses the contribution of terms in a lm model.\n")
  cat("   It expects a vector of names and a lm.object to update.\n")
  cat("   as in script.name(facvec,base.lm).\n")
  stop()
}
a_0
i_0
base.r2_summary(base.lm)$r.squared
for (i in 1:length(facvec)){
  a[i]_c(fac=summary(update(base.lm,.~.+as.name(facvec[i])))$r.squared-base.r2)
  i_i+1
}
return(a)
}


Thanks for any help,
adrian
acuster at nature.berkeley.edu


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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