View source: R/formula_utils.R
formula_term_labels | R Documentation |
This function extracts the term labels from the right-hand side of a given R formula. If an intercept is to be included (and a name for the intercept is provided), it will be added as the first element of the returned vector.
formula_term_labels(formula, intercept = "(Intercept)")
formula |
An R formula, e.g. ~ x1 * x2. |
intercept |
A character string indicating the name for the intercept. The default value is "(Intercept)". If NULL is provided, the intercept will not be included, even if present in the formula. |
The default intercept value, "(Intercept)", is chosen to be consistent with the intercept label
returned by functions such as stats::lm()
, stats::model.matrix()
, and similar modeling functions.
A character vector containing the term labels. If an intercept is present and intercept is not NULL, the intercept is returned first, followed by the remaining terms.
This function is documented by ChatGPT after some discussion.
# With intercept:
formula_term_labels(~ x1 * x2)
# Without intercept:
formula_term_labels(~ x1 * x2, intercept = NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.