I have a string "California Art Craft Painting Society" and I want to write a function x in R that can turn any string into an acronym "CACPS". I used the following code:
acronym <- function(x){
abbreviate(x)
}
Is there a way to write the function using stringr such as strsplit the string first, then use strsub to pull the first letter of each word (not use abbreviate)?
This might be of use. It uses str_remove_all on characters which are not preceded by a word break, and also removes any spaces.
library(stringr)
create_acronym <- function(x){
str_remove_all(x , "(?<!\\b)\\w|\\s" )
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With