Skip to content
Prev 169104 / 398506 Next

How to show variables used in lm function call?

Pick off the names in the first two lines of the function body
and then paste them into a formula, converting to a real
formula object and then make your call:

mylm <- function(dep, indep, env = parent.frame()) {
	depnm <- deparse(substitute(dep))
	indepnm <- deparse(substitute(indep))
	fo <- sprintf("%s ~ lag(%s, -1) + %s", depnm, depnm, indepnm)
	fo <- as.formula(fo, env = env)
	do.call(dyn$lm, list(fo))
}

library(dyn)
x <- zoo(1:10)
y <- x*x
mylm(y, x)
On Tue, Feb 3, 2009 at 12:16 PM, Pele <drdionc at yahoo.com> wrote: