ft_regex_freq | R Documentation |
Reorders the levels of a factor vector based on the frequency of substrings matching a regular expression.
ft_regex_freq(
factor_vec,
pattern,
case = FALSE,
decreasing = TRUE,
inplace = TRUE
)
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 |
A factor vector with levels reordered based on the frequency of matched substrings.
Kai Guo
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.