I need to write a basic regular expression in R that I cannot figure out. What I am trying to do is to remove the number and space from the data, so that “Flagstaff 24” becomes “Flagstaff”.
library(stringr)
data <- c("Flagstaff 24", "Los Angeles 23", "Cleveland 29", "Cleveland 29", "Seattle 22")
However as my numbers are either one or two digits I cannot just trim the end. What I have tried are the following expressions that do not work:
str_split_fixed(data, ".\\d", 1)
I’m trying to wrap my head around these expression structures!
You can just use
gsub()for this. (No need for thestringrpackage.)