英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论