Guru's Verification engine ensures consistency, confidence, and trust in the knowledge your organization shares. Learn more.

R | Formulas (~ form)

Formulas in R are a way for the language to capture relationships between variables, without evaluating the expression. They take the form of independent and dependent variables related by a tilde, i.e. y ~ f(x).

Formulas aren't to be evaluated in isolation like most other expressions—they are typically passed into a function and handled individually by that function.

Examples:

y ~ x + 1 # bare formula~ x + 1 # it's possible to only have the righthand sidestats::lm(y ~ x + 1, data = some_data) # how a formula would typically be used as an input; here x and y are column variables of `some_data`stats::lm(y ~ ., data = some_data) # the dot here means "all columns not in the rest of the formula", so all columns in `some_data` that is not ypurrr::map(list(1, 2, 3), ~.x + 1) # example of rhs-only formula being used by a function

Resources:

You must have Author or Collection Owner permission to create Guru Cards. Contact your team's Guru admins to use this template.