Skip to contents

`strg_numeric_order` orders factor levels numerically based on the values in the input vector. If `rev` is set to `TRUE`, the levels are reversed.

Usage

strg_numeric_order(col, rev = TRUE)

Arguments

col

A factor or character vector.

rev

Logical; if `TRUE`, reverse the order of levels.

Value

A factor with reordered levels.

Details

This function is useful for ensuring that factor levels are ordered correctly when dealing with numeric values. It leverages the `stringr::str_sort` function to sort the levels.

Examples

if (FALSE) { # \dontrun{
temp_df = paste0("lab_", seq(1, 50, 2)) %>%
data.frame(label_unordered = .
           ,label_ordered = strg_numeric_order(.))

temp_df %>% arrange(label_unordered) %>% print()
temp_df %>% arrange(desc(label_ordered)) %>% print()

} # }