如何修改公式的左侧?

fhe*_*anb 5 r

我想mu.fo用存储在response变量中的值来修改公式的左侧。这个想法是要获得一个像这样的新公式:profit ~ x1 + x2但是实际上我得到了response ~ x1 + x2

如何response自动使用存储在变量中的值?

response <- 'profit'
mu.fo <- ~ x1 + x2
update.formula(mu.fo, response ~ .)
Run Code Online (Sandbox Code Playgroud)

Hac*_*k-R 2

response <- 'profit'
mo.fo <- ~ x1 + x2
mo.fo <- as.formula(paste(response, "~ x1+x2"))
mo.fo

profit ~ x1 + x2
Run Code Online (Sandbox Code Playgroud)