gpt4 book ai didi

string - 删除 R 中除撇号和字内破折号之外的标点符号

转载 作者:行者123 更新时间:2023-12-01 07:26:14 25 4
gpt4 key购买 nike

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

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"

关于string - 删除 R 中除撇号和字内破折号之外的标点符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24550620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com