I have a data frame
a <- runif (10) b <- letters [1:10] c <- c(rep (\"A-B\", 4), rep(\"A_C\", 6)) data1 <- data.frame (a, b, c) data1
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)