我的数据如下
location<- c("xyz, sss, New Zealand", "USA", "Pris,France")
id<- c(1,2,3)
df<-data.frame(location,id)
我想从数据中提取国家名称。棘手的部分是如果我只提取最后一个单词,那么我将只有一个记录(法国)。
library(stringr)
df$country<- word(df$location,-1)
关于如何从这些数据中提取国家数据的任何想法?
id location country
1 xyz, sss, New Zealand New Zealand
2 USA USA
3 Pris,France France