[R] building formula objects
Russell Senior
seniorr at aracnet.com
Wed Jul 10 04:42:51 CEST 2002
>>>>> "Thomas" == Thomas Lumley <tlumley at u.washington.edu> writes:
Thomas> This is what I regard as the canonical example of do.call()
Thomas> If these were separate variables instead of elements of tmp
Thomas> you could do eg rbind(twa, twa.bh, rcm, rcm, s25, s5) But they
Thomas> aren't, so do.call("rbind", tmp) does the trick. This creates
Thomas> a call to rbind() where the arguments are the elements of tmp.
Ah, thank you! Your precise do.call() didn't quite do the trick for
me, but it was easy to munge into the right form. I've also now
abstracted it a little more:
russell <- function(resp,fact,data) {
f <- function(n) {
command.string <- paste("try(anova(lm(X ~ Y, data=data)))",
sep="")
command <- parse(text = command.string)[[1]]
command.sub <- do.call("substitute",
list(command,
list(X = as.name(n),
Y = as.name(fact))))
eval(command.sub)
}
do.call("rbind",apply(t(sapply(resp,f)),1,as.data.frame))
}
I need a better name, but otherwise I am a happy guy. Thank you all
for your help!
--
Russell Senior ``The two chiefs turned to each other.
seniorr at aracnet.com Bellison uncorked a flood of horrible
profanity, which, translated meant, `This is
extremely unusual.' ''
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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