On 28.03.2017, at 16:57, peter dalgaard <pdalgd at gmail.com> wrote:
On 28 Mar 2017, at 16:14 , S?ren Vogel <soeren.vogel at posteo.ch> wrote:
Hello
Ho can I apply a formula to a data frame?
That would depend on whether the formula has any special interpretation.
If if is just an elementary expression, then it would be like
eval(For1[[3]], Data, environment(For1))
but you are using "." to represent... what exactly?
One possibility is model.matrix(For1, Data)
but I'm not at all sure that that is what you want.
-pd
library("formula.tools")
Data <- data.frame("v1" = rnorm(31), "v2" = runif(31), "v3" = sample(1:7, 31, repl=T), "v4" = rlnorm(31))
For1 <- as.formula(v1 ~ .^3)
Lhs <- Data[, formula.tools::lhs.vars(formula)]
Rhs <- apply_formula_to_data_frame_and_return_result(data, formula) # ???
Thank you,
S?ren