I'm trying to do something but can't remember/find the answer. I have a list of city names from the Census Bureau and they put the city's type on the end which is messing up my match()
.
I'd like to make this:
Middletown Township
Sunny Valley Borough
Hillside Village
into this:
Middletown
Sunny Valley
Hillside
Any suggestions? Ideally I'd also like to know if there's a lastIndexOf()
function in R.
Here's the data:
df1 <- data.frame(
id = c(1, 2, 3),
city = factor(c("Middletown Township", "Sunny Valley Borough", "Hillside Village"))
)