![](/img/trans.png)
[英]How to replace a word by another using if statement and str_replace in 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.