I am a beginner with R. Now, I have a vector in a data.frame like this
city Kirkland, Bethesda, Wellington, La Jolla, Berkeley, Costa, Evie KW172NJ Miami, P
You could use regexpr to find the position of the first comma in each element and use substr to snip them at this:
regexpr
substr
x <- c("London, UK", "Paris, France", "New York, USA") substr(x,1,regexpr(",",x)-1) [1] "London" "Paris" "New York"