Replacing entire string when a single word is in the string R -


i wondering if had come across solution problem when cleaning data in r. idea have list of strings example:

strings = c("hello world", "goodbye all", "help appreciated", "hello sam") 

then go through list of strings , whenever word found entire string replaced.

therefore if looking word "hello" replaced "math"

so output looking be:

"math", "goodbye all", "help appreciated", "math". 

any or ideas appreciated.

just use grepl:

strings = c("hello world", "goodbye all", "help appreciated", "hello sam") > strings[grepl("hello",strings)] <- "math" > strings [1] "math"                "goodbye all"         "help appreciated" "math"    

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -