To remove a specific word from a string using the stringr package in R, you can use the str_remove_all() function. Here's an example:

library(stringr)

# Original string
string <- 'This is a sample string to remove the word 'sample'.'

# Word to remove
word <- 'sample'

# Remove the word from the string
new_string <- str_remove_all(string, word)

# Print the new string
print(new_string)

Output:

[1] "This is a  string to remove the word '.'."

In the above example, the function str_remove_all() is used to remove all occurrences of the word 'sample' from the given string. The resulting string is stored in the new_string variable and then printed.

Remove Specific Word from String in R with stringr Package

原文地址: https://www.cveoy.top/t/topic/y7G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录