iterative_ordering: iterativeOrdering

View source: R/utilities.R

iterative_orderingR Documentation

iterativeOrdering

Description

Turn the chosen columns (factor) of the input data.frame into ordered factors. For each factor, the order is given by the number of elements in each level of that factor.

Usage

iterative_ordering(df, var_names, i = 1, decreasing = TRUE)

Arguments

df

a data.frame object.

var_names

character vector containing the names of one or more columns of df.

i

iteration index (default i = 1).

decreasing

logical value or a vector of them. Each value should be associated to a var_name vector's element. Should the sort order be increasing or decreasing?

Value

the input data.frame with the var_names variables as ordered factors.

See Also

plotMutualFindings

Examples

# From a dataset with some factor columns
mpg <- data.frame(ggplot2::mpg)
# Order the levels of the desired factors based on the cardinality of each
# level.
ordered_mpg <- iterative_ordering(df = mpg,
   var_names = c("manufacturer", "model"),
   decreasing = c(TRUE, TRUE))
# Now the levels of the factors are ordered in a decreasing way
levels(ordered_mpg$manufacturer)
levels(ordered_mpg$model)

mcalgaro93/benchdamic documentation built on Sept. 26, 2024, 6:34 p.m.