Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to turn one symbol into another

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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"))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading