R: combine several gsub() function in a pipe

前端 未结 4 1702
野性不改
野性不改 2021-02-05 21:21

To clean some messy data I would like to start using pipes %>%, but I fail to get the R code working if gsub() is not at the beginning of the pipe,

4条回答
  •  无人共我
    2021-02-05 21:55

    You can use str_replace(string, pattern, replacement) from package stringr as a drop-in replacement for gsub. stringr functions follow a tidy approach in which the string / character vector is the first argument.

    c("hello", "hi") %>% str_replace_all("[aeiou]", "x")
    

    See Introduction to stringr for more information on stringr's sensibly named and defined functions as replacements for R's default string functions.

提交回复
热议问题