Hello all,

Say I would like to change the outcome in a formula to a variable not part of 
the original dataset. This works just fine:

res <- lm(mpg ~ wt + cyl, data=mtcars)
res
y <- rnorm(nobs(x))
update(x, formula = y ~ .)

But not when doing so within a function:

rm(y)

f <- function(x) {
   y <- rnorm(nobs(x))
   update(x, formula = y ~ .)
}

f(res)

Is there a way to make this work? Using y <<- ... inside the function works, 
but I would like to avoid such a heavy-handed approach.

Best,
Wolfgang

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to