ft_regex_freq {fctutils} | R Documentation |
Reorder Factor Levels Based on Regex Pattern Frequency
Description
Reorders the levels of a factor vector based on the frequency of substrings matching a regular expression.
Usage
ft_regex_freq(
factor_vec,
pattern,
case = FALSE,
decreasing = TRUE,
inplace = TRUE
)
Arguments
factor_vec |
A factor vector whose levels are to be reordered. |
pattern |
A string representing the regular expression pattern to match. |
case |
Logical. Should the pattern matching be case-sensitive? Default is |
decreasing |
Logical. Should the ordering be decreasing by frequency? Default is |
inplace |
Logical. If |
Value
A factor vector with levels reordered based on the frequency of matched substrings.
Author(s)
Kai Guo
Examples
# Example factor vector
factor_vec <- factor(c('apple', 'banana', 'apricot', 'cherry', 'blueberry', 'blackberry', 'date'))
# Reorder based on pattern matching 'a'
ft_regex_freq(factor_vec, pattern = 'a')
# Reorder with case-sensitive matching
ft_regex_freq(factor_vec, pattern = '^[A-Z]', case = TRUE)
[Package fctutils version 0.0.7 Index]