allows option to manually set the first level of the factor, for consistency with yardstick which automatically considers the first level as the "positive class" when evaluating classification.

set_fct(
  .data,
  ...,
  first_level = NULL,
  order_fct = FALSE,
  labels = NULL,
  max_levels = Inf
)

# S3 method for data.frame
set_fct(.data, ..., first_level = NULL, order_fct = FALSE, max_levels = Inf)

# S3 method for default
set_fct(.data, ..., first_level = NULL, order_fct = FALSE, max_levels = Inf)

Arguments

.data

dataframe

...

tidyselect (default selection: all character columns)

first_level

character string to set the first level of the factor

order_fct

logical. ordered factor?

labels

chr vector of labels, length equal to factor levels

max_levels

integer. uses fct_lump_n to limit the number of categories. Only the top max_levels are preserved, and the rest being lumped into "other"

Value

tibble

Examples


## simply set the first level of a factor

iris$Species %>% levels
#> [1] "setosa"     "versicolor" "virginica" 

iris %>%
  set_fct(Species, first_level = "virginica") %>%
  dplyr::pull(Species) %>%
  levels()
#> [1] "virginica"  "setosa"     "versicolor"