Get the strings before the comma with R
Just for fun, you can use strsplit
> x <- c("London, UK", "Paris, France", "New York, USA")
> sapply(strsplit(x, ","), "[", 1)
[1] "London" "Paris" "New York"
You can use gsub
with a bit of regexp :
cities <- gsub("^(.*?),.*", "\\1", df$city)
This one works, too :
cities <- gsub(",.*$", "", df$city)