从包含州和县信息的字符串中,我想分为两列,来自州和县。使用函数separate
,甚至使用模式","
,或变体为"[,]"
,"[\\,]"
和"\\,"
,但我继续将我的字符串分割在空格上,而不是模式。
见例子
data.frame(test = c("montana,sheridan",
"north dakota,divide",
"new york,clinton")) %>%
separate(test, c("state", "county"), by=",", extra = "drop")
我认为你提出错误的论点。使用sep = ","
而不是by = ","
。
test = c("montana,sheridan",
"north dakota,divide",
"new york,clinton")
data.frame(test) %>%
separate(test, c("state", "county"),
sep=",", extra = "drop")
这对我有用。我希望你觉得这有帮助。