【发布时间】:2019-06-26 17:56:19
【问题描述】:
我想 dplyr::separate 必须在空格之后和大写字母之前的减号 (-)。
我的正则表达式 [\s]-[A-Z] 包含空格和大写字母,因此通过分隔删除。我只想在该特定位置使用减号进行分隔,而不是去掉空格和后面的字母。
library(dplyr)
data.frame(x = c("Hans-Peter Wurst -My Gosh", "What is -wrong here -Do not worry")) %>%
separate(x, into = c("one", "two"), sep = "[\\s]-[A-Z]")
结果:
# one two
# 1 Hans-Peter Wurst y Gosh
# 2 What is -wrong here o not worry
期望的输出是:
# one two
# 1 Hans-Peter Wurst My Gosh
# 2 What is -wrong here Do not worry
【问题讨论】:
-
好的,我重新打开它,因为我对这些谈话感到头疼