【问题标题】:tidyr separate error when use sep parenthesis使用 sep 括号时出现 tidyr 单独错误
【发布时间】:2016-09-06 04:06:54
【问题描述】:

我无法使用括号作为分隔符来分隔列:

d = data.frame(a = c('af(dsf', 'sdf (asdf', 'sdf(df'))
d %>% separate(a, c('a','b'), sep = '(')

stringi::stri_split_regex(value, sep, n_max) 中的错误:不正确 正则表达式模式中的嵌套括号。 (U_REGEX_MISMATCHED_PAREN)

有错误吗?提前致谢。

【问题讨论】:

  • 改用sep = '\\('
  • 谢谢。它有效。!

标签: r tidyr


【解决方案1】:

我们不需要在这里明确指定sep,因为它会自动检测

separate(d, a, c("a", "b"))
#    a    b
#1  af  dsf
#2 sdf asdf
#3 sdf   df

如果需要指定,可以在 cmets 中转义 (\\() 或将其放在方括号中

separate(d, a, c("a", "b"), sep="[(]")
#    a    b
#1   af  dsf
#2 sdf  asdf
#3  sdf   df

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    • 2021-02-27
    • 1970-01-01
    • 2013-12-11
    • 2013-12-23
    • 1970-01-01
    相关资源
    最近更新 更多