View source: R/single_filter.R
ft_filter_pos | R Documentation |
Removes factor levels where a specified character appears at specified positions within the levels.
ft_filter_pos(
factor_vec,
positions = NULL,
char,
case = FALSE,
remove_na = TRUE,
invert = FALSE,
.return = FALSE
)
factor_vec |
A factor vector from which levels will be removed. |
positions |
A vector of positive integers indicating the character positions to check. |
char |
A single character string specifying the character to look for. |
case |
Logical. Should the character matching be case-sensitive? Default is |
remove_na |
remove NA from the output? Default is |
invert |
logical. If TRUE return indices or values for elements that do not match. |
.return |
logical. If TRUE return TRUE or FALSE instead of element. |
A factor vector with levels removed where the specified character appears at the specified positions.
Kai Guo
# Example factor vector
factor_vec <- factor(c('apple', 'banana', 'apricot', 'cherry', 'date', 'fig', 'grape'))
# Remove levels where 'a' appears at position 1
ft_filter_pos(factor_vec, positions = 1, char = 'a')
# Remove levels where 'e' appears at positions 2 or 3
ft_filter_pos(factor_vec, positions = c(2, 3), char = 'e')
# Case-sensitive removal
factor_vec_case <- factor(c('Apple', 'banana', 'Apricot', 'Cherry', 'Date', 'Fig', 'grape'))
ft_filter_pos(factor_vec_case, positions = 1, char = 'A', case = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.