string – 删除除撇号和R中的字内短划线之外的标点符号

我知道如何单独删除标点并保留撇号:

gsub( "[^[:alnum:]']"," ",db$text )

或者如何使用tm包保持字内短划线:

removePunctuation(db$text,preserve_intra_word_dashes = TRUE)

但我无法找到同时做到这两点的方法.例如,如果我的原始句子是:

"Interested in energy/the environment/etc.? Congrats to our new e-board! Ben,Nathan,Jenny,and Adam,y'all are sure to lead the club in a great direction next year! #obama #swag"

我希望它是:

"Interested in energy the environment etc Congrats to our new e-board Ben Nathan Jenny and Adam y'all are sure to lead the club in a great direction next year obama swag"

当然,会有额外的空白区域,但我可以在以后删除它们.

我将非常感谢你的帮助.

解决方法

使用 character classes

gsub("[^[:alnum:]['-]",db$text)

## "Interested in energy the environment etc Congrats to our new e-board Ben Nathan Jenny and Adam y'all are sure to lead the club in a great direction next year obama swag"

相关文章

HTML代码中要想改变字体颜色,常常需要使用CSS样式表。CSS是...
HTML代码如何让字体盖住图片呢?需要使用CSS的position属性及...
HTML代码字体设置 在HTML中,我们可以使用标签来设置网页中的...
在网页设计中,HTML代码的字体和字号选择是非常重要的一个环...
HTML(Hypertext Markup Language,超文本标记语言)是一种用...
外链是指在一个网页中添加一个指向其他网站的链接,用户可以...