使用stringr::str_remove_all如何移除一个字符串?

huangapple go评论54阅读模式
英文:

How to remove a string using stringr::str_remove_all?

问题

9, 6.5, 8.5, 10, 7.5
英文:

Here is the data I have:

X <- c("9 % vol.", "6.5 % vol.", "8.5 % vol.", "10 % vol.", "7.5 % vol.")

I want to turn X into a numeric vector looking like:

9, 6.5, 8.5, 10, 7.5

I tried the following code:

stringr::str_remove_all(x, "[ //%//vol.]")

But, this code gives me the following outcome:

[1] "9"  "65" "85" "10" "75"

How can I modify this code so that I get the output I want? Thanks.

答案1

得分: 1

"modify your code to:"

stringr::str_remove_all(X, "( % vol.)")

"output would be:"

"9" "6.5" "8.5" "10" "7.5"

英文:

modify your code to:

stringr::str_remove_all(X, "( % vol.)")

output would be:

"9"   "6.5" "8.5" "10"  "7.5"

huangapple
  • 本文由 发表于 2023年5月6日 22:11:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189353.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定