Use of string_replace()

My data looked like this

head(ttrigram)
word1 word2 frequency
1 enjoying_case presentations 77
2 case_presentations students 77
3 presentations_students w 77
4 students_w good 77
5 w_good luck 77
6 good_luck students 77

I was trying to replace the underscores in word1 with blanks: My code was:
library(stringr)
ttrigram$word1<- string_replace(ttrigram$word1, "_", " ")

I get this message on the console:
Error in string_replace(ttrigram$word1, "", " ") :
could not find function "string_replace"
I also tried this using mutate() and got a similar error message.
ttrigram<- mutate(ttrigram, wordedit= string_replace_all(word1, "
", " "))
Error in string_replace_all(word1, "_", " ") :
could not find function "string_replace_all"

Thank you for your help.

The function in stringr is called str_replace.

library(stringr)
x <- c("asdf_lkjl", "QWEWE_lioun", "T_Y")
x_new <- str_replace(x, "_", " ")
x_new
#> [1] "asdf lkjl"   "QWEWE lioun" "T Y"

Created on 2019-05-29 by the reprex package (v0.2.1)

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.