Learn R Programming

arsenal (version 0.5.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 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.

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"))

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

# }

Run the code above in your browser using DataLab