【问题标题】:Issue with str_replace for scraped data抓取数据的 str_replace 问题
【发布时间】:2020-07-30 04:22:48
【问题描述】:

我正在尝试使用删除数据集中的一列单词中的撇号

str_replace(tidy_posts$word, "'", "")

但它返回的向量仍然包含撇号。向量的类是字符,所以我不明白为什么这不起作用。我唯一的猜测是,因为这些词来自我从 reddit API 获得的数据,所以编码很时髦之类的。

edit: "[:punct:]" 也不起作用。

【问题讨论】:

    标签: r dplyr str-replace


    【解决方案1】:

    当您有一些“特殊”标点符号(例如 .')时,在正则表达式中选择它们的方法是在感兴趣的标点符号之前使用 \\。这个例子可以帮助你:

    ch = c("The vector's class is character, so I can't understand why this won't work")
    
    > stringr::str_replace_all(ch, "\\'","")
    
    [1] "The vectors class is character, so I cant understand why this wont work"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-29
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      • 2020-06-28
      相关资源
      最近更新 更多