Get the strings before the comma with R

后端 未结 5 528
清酒与你
清酒与你 2020-12-31 07:16

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         


        
5条回答
  •  不知归路
    2020-12-31 07:53

    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"
    

提交回复
热议问题