小编Cra*_*oot的帖子

如何在 R 中根据第一个空格拆分列

我有这段代码可以在第二个空间上拆分列,但我不知道如何修改它以仅在第一个空间上拆分。我对正则表达式不太熟悉。

library(tidyr)

df <- data.frame(Location = c("San Jose CA", "Fremont CA", "Santa Clara CA"))
separate(df, Location, into = c("city", "state"), sep = " (?=[^ ]+$)")

#          city state
# 1    San Jose    CA
# 2     Fremont    CA
# 3 Santa Clara    CA
Run Code Online (Sandbox Code Playgroud)

regex string r regex-lookarounds

1
推荐指数
1
解决办法
3585
查看次数

标签 统计

r ×1

regex ×1

regex-lookarounds ×1

string ×1