I have many different characters which have the following structure:
# Example x <- "char1, char2, char3"
I want to remove the last comma of this character with " &", i.e. the desired output should look as follows:
# Desired output "char1, char2 & char3"
How could I replace the last comma of a character with " &"?
One option is
library(stringi) stri_replace_last(x, fixed = ',', ' &') # "char1, char2 & char3"