【发布时间】:2016-01-08 18:13:08
【问题描述】:
我一直在寻找有关 Stackoverflow 的解决方案并在 R (RStudio) 中试验了几个小时。我知道如何删除标点符号,同时使用 gsub(不是 tm 包,但我想知道是否有人可以提供有关此操作的提示)与以下问题同时进行)。我想知道如何防止将单词与 gsub 或任何其他正则表达式过程连接起来,而我曾经删除过的标点符号在哪里。到目前为止,这是我能做的最好的:
x <-"Good luck!!!!SPRINT I like good deals. I can't lie brand-new stuff---- excites me got&&&&& to say yo, At&t why? a* dash-- apostrophe's''' I can do all-day. But preventing%%%%concatenating is a new**$ballgame but----why--- not?"
gsub("(\\w['&-]\\w)|[[:punct:]]", "\\1", x, perl=TRUE)
#[1] "Good luckSPRINT I like good deals I can't lie brand-new stuff excites me got to say yo At&t why a dash apostrophe's I can do all-day But preventingconcatenating is a newballgame butwhy not"
有什么想法吗?顺便说一句,这个问题的目的是将解决方案应用于数据框列或社交媒体帖子的语料库。
【问题讨论】: