SyntaxFix
Write A Post
Hire A Developer
Questions
chartr is also convenient for these types of substitutions:
chartr
chartr("_", "-", data1$c) # [1] "A-B" "A-B" "A-B" "A-B" "A-C" "A-C" "A-C" "A-C" "A-C" "A-C"
Thus, you can just do:
data1$c <- chartr("_", "-", data1$c)