Aliases: formula formula.default formula.formula formula.terms formula.data.frame DF2formula as.formula print.formula [.formula
Keywords: models
### ** Examples class(fo <- y ~ x1*x2) # "formula"
[1] "formula"
fo
y ~ x1 * x2 <environment: 0x55ccff66c8a0>
typeof(fo) # R internal : "language"
[1] "language"
terms(fo)
y ~ x1 * x2 attr(,"variables") list(y, x1, x2) attr(,"factors") x1 x2 x1:x2 y 0 0 0 x1 1 0 1 x2 0 1 1 attr(,"term.labels") [1] "x1" "x2" "x1:x2" attr(,"order") [1] 1 1 2 attr(,"intercept") [1] 1 attr(,"response") [1] 1 attr(,".Environment") <environment: 0x55ccff66c8a0>
environment(fo)
<environment: 0x55ccff66c8a0>
environment(as.formula("y ~ x"))
<environment: 0x55ccff66c8a0>
environment(as.formula("y ~ x", env = new.env()))
<environment: 0x55ccfdcb2090>
## Create a formula for a model with a large number of variables: xnam <- paste0("x", 1:25) (fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+"))))
y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 + x23 + x24 + x25 <environment: 0x55ccff66c8a0>
## Equivalent with reformulate(): fmla2 <- reformulate(xnam, response = "y") stopifnot(identical(fmla, fmla2))