tidy_select_variables: Select variables to keep/drop

View source: R/tidy_select_variables.R

tidy_select_variablesR Documentation

Select variables to keep/drop

Description

Will remove unselected variables from the results. To remove the intercept, use tidy_remove_intercept().

Usage

tidy_select_variables(x, include = everything(), model = tidy_get_model(x))

Arguments

x

(data.frame)
A tidy tibble as produced by ⁠tidy_*()⁠ functions.

include

(tidy-select)
Variables to include. Default is everything(). See also all_continuous(), all_categorical(), all_dichotomous() and all_interaction().

model

(a model object, e.g. glm)
The corresponding model, if not attached to x.

Details

If the variable column is not yet available in x, tidy_identify_variables() will be automatically applied.

Value

The x tibble limited to the included variables (and eventually the intercept), sorted according to the include parameter.

See Also

Other tidy_helpers: tidy_add_coefficients_type(), tidy_add_contrasts(), tidy_add_estimate_to_reference_rows(), tidy_add_header_rows(), tidy_add_n(), tidy_add_pairwise_contrasts(), tidy_add_reference_rows(), tidy_add_term_labels(), tidy_add_variable_labels(), tidy_attach_model(), tidy_disambiguate_terms(), tidy_identify_variables(), tidy_plus_plus(), tidy_remove_intercept()

Examples

df <- Titanic |>
  dplyr::as_tibble() |>
  dplyr::mutate(Survived = factor(Survived))
res <-
  glm(Survived ~ Class + Age * Sex, data = df, weights = df$n, family = binomial) |>
  tidy_and_attach() |>
  tidy_identify_variables()

res
res |> tidy_select_variables()
res |> tidy_select_variables(include = "Class")
res |> tidy_select_variables(include = -c("Age", "Sex"))
res |> tidy_select_variables(include = starts_with("A"))
res |> tidy_select_variables(include = all_categorical())
res |> tidy_select_variables(include = all_dichotomous())
res |> tidy_select_variables(include = all_interaction())
res |> tidy_select_variables(
  include = c("Age", all_categorical(dichotomous = FALSE), all_interaction())
)

broom.helpers documentation built on Sept. 11, 2024, 6:31 p.m.