ft_filter_pos {fctutils} | R Documentation |
Remove Factor Levels with Specific Characters at Specified Positions
Description
Removes factor levels where a specified character appears at specified positions within the levels.
Usage
ft_filter_pos(
factor_vec,
positions = NULL,
char,
case = FALSE,
remove_na = TRUE,
invert = FALSE,
.return = FALSE
)
Arguments
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. |
Value
A factor vector with levels removed where the specified character appears at the specified positions.
Author(s)
Kai Guo
Examples
# 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)
[Package fctutils version 0.0.7 Index]