`separate()`函数来自tidyr分裂空间而不是模式

问题描述 投票:0回答:1

从包含州和县信息的字符串中,我想分为两列,来自州和县。使用函数separate,甚至使用模式",",或变体为"[,]""[\\,]""\\,",但我继续将我的字符串分割在空格上,而不是模式。

见例子

data.frame(test = c("montana,sheridan",
                    "north dakota,divide",
                    "new york,clinton")) %>%
  separate(test, c("state", "county"), by=",", extra = "drop")

r tidyr separator
1个回答
0
投票

我认为你提出错误的论点。使用sep = ","而不是by = ","

test = c("montana,sheridan",
     "north dakota,divide",
     "new york,clinton")
data.frame(test) %>%
     separate(test, c("state", "county"),
     sep=",", extra = "drop")

这对我有用。我希望你觉得这有帮助。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.