#Create vector of strings
vec <- c("Rose", "Thistle", "Leek", "Shamrock")
#View vector
vec[1] "Rose" "Thistle" "Leek" "Shamrock"
The function stringr::str_counts() counts the number of matches to a pattern/regular expression within each element of a string vector.
Prior to using the function create a vector of strings.
[1] "Rose" "Thistle" "Leek" "Shamrock"
You can specify a string pattern to be used for detection.
The function is case-sensitive. “R” will detect “Rose” but not “shamrock”.
The function works with various regular expressions.
Count number of letters between A-M (inclusive), lower or upper case.