繁体   English   中英

如何将特定单词替换为 R 中的另一个单词

[英]how to replace a specific word into another word in R

我在 gsub 中寻找代码以将特定单词替换为 xx 像这样。

x <- c("replace #bitcoin and not #bitoinusdha", "replace #btc and not #btcasdasd")

View(x)
[1] replace  xx and not #bitcoinusdha
[2] replace xx and not #btcasdasd

希望有人可以帮助我。

问候,

奥托

假设要替换的短语总是以#abc...开头,然后在每个模式的末尾使用单词边界并搜索任一值。

x <- c("replace #bitcoin and not #bitcoinusdha", "replace #btc and not #btcasdasd")
gsub("#bitcoin\\b|#btc\\b", "xx", x)
#> [1] "replace xx and not #bitcoinusdha" "replace xx and not #btcasdasd"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM