# Example factor vector
factor_vec <- factor(c('apple_pie', 'banana_bread', 'cherry_cake'))
# Replace '_pie', '_bread', '_cake' with '_dessert' (all occurrences)
ft_replace_pattern(factor_vec, pattern = '_.*', replacement = '_dessert')
# Replace only the first occurrence of '_' with '-'
ft_replace_pattern(factor_vec, pattern = '_', replacement = '-', replace_all = FALSE)
Run the code above in your browser using DataLab