Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. x <- gsub("'", "", x)
  2. x <- gsub(" ", "_", x)
  3.  
  4. x <- chartr("' ", "_", x)
  5. #Error in chartr("' ", "_", "a'b c") : 'old' is longer than 'new'
  6.  
  7. library(gsubfn)
  8. gsubfn(".", list("'" = "", " " = "_"), x)
  9. # [1] "ab_c"
  10.  
  11. library(magrittr)
  12.  
  13. x <- "a'b c"
  14.  
  15. x %<>%
  16. gsub("'", "", .) %>%
  17. gsub(" ", "_", .)
  18. x
  19. ##[1] "ab_c"
  20.  
  21. gsub("\s", "", chartr("' ", " _", x)) # Use whitespace and then remove it
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement