【发布时间】:2021-11-07 03:36:12
【问题描述】:
我有一个包含一列的 excel 文件。此列有一个数字和与此数字对应的状态。
| State |
|---|
| 01 Alabama |
| 02 Alaska |
等等。我想将此列提取为两列,一列包含数字,另一列包含州名。我尝试使用 tidyr 中的 extract():
df <- read_xlsx("States.xlsx")
df %>% tidyr::extract(States,c("A","B"),sep="(\\d\\d) ([a-zA-Z]+)")
但是,它会吐出错误:
Error: `regex` should define 2 groups; found.
Error: 1 components of `...` were not used.
We detected these problematic arguments:
* `sep`
Did you misspecify an argument?
任何想法我做错了什么?谢谢!
【问题讨论】:
标签: r dplyr split extract tidyr