arsenal (version 2.0.0)

formulize: formulize

Description

A shortcut to generate one-, two-, or many-sided formulas from vectors of variable names.

Usage

formulize(y = "", x = "", ..., data = NULL)

Arguments

y, x, ...

Character vectors, names, or calls to be collapsed (by "+") and put left-to-right in the formula. If data is supplied, these can also be numeric, denoting which column name to use. See examples.

data

An R object with non-null column names.

See Also

reformulate

Examples

Run this code
# NOT RUN {
## two-sided formula
formulize("y", c("x1", "x2", "x3"))

## one-sided formula
formulize(x = c("x1", "x2", "x3"))

## multi-sided formula
formulize("y", c("x1", "x2", "x3"), c("z1", "z2"), "w1")

## can use numerics for column names
data(mockstudy)
formulize(y = 1, x = 2:4, data = mockstudy)

## mix and match
formulize(1, c("x1", "x2", "x3"), data = mockstudy)

## get an interaction
formulize("y", c("x1*x2", "x3"))

## no intercept
formulize("y", "x1 - 1")
formulize("y", c("x1", "x2", "-1"))

## use in an lm
form <- formulize(2, 3:4, data = mockstudy)
summary(lm(form, data = mockstudy))

## using non-syntactic names or calls (like reformulate example)
formulize(as.name("+-"), c("`P/E`", "`% Growth`"))

f <- Surv(ft, case) ~ a + b
formulize(f[[2]], f[[3]])
# }

Run the code above in your browser using DataCamp Workspace