Im trying to find a way to substitute out the "|" symbol in this dataset for the "/" symbol df<-c(2|4,5|6,3|4,4|7,5|8) So that way the final would look like df<-c(2/4,5/6,3/4,4/7,5/8)
Any help would be great thankyou
CodePudding user response:
If it is a single string (or a vector of elements) use chartr
from base R
chartr("|", "/", df)
[1] "2/4,5/6,3/4,4/7,5/8"
df2$col1 <- chartr("|", "/", df2$col1)
> df2
col1
1 2/4
2 5/6
3 3/4
4 4/7
5 5/8
data
df <- "2|4,5|6,3|4,4|7,5|8"
df2 <- data.frame(col1 = c("2|4", "5|6", "3|4", "4|7", "5|8"))