Re: [R] Using update() within a function with a changed formula

2021-11-13 Thread Wolfgang Viechtbauer
Perfectly clear. Thanks! Best, Wolfgang On Sat, 13 Nov 2021, Duncan Murdoch wrote: On 13/11/2021 2:24 p.m., Viechtbauer, Wolfgang (SP) wrote: 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 ~

Re: [R] Using update() within a function with a changed formula

2021-11-13 Thread Duncan Murdoch
On 13/11/2021 2:24 p.m., Viechtbauer, Wolfgang (SP) wrote: 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 whe

[R] Using update() within a function with a changed formula

2021-11-13 Thread Viechtbauer, Wolfgang (SP)
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