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

paste two strings to achieve a desired combination

I was wondering how to paste() g and h to obtain my desired combination shown below?

g <- c("compare","control")
h <- "Correlation"

paste0(h, g, collapse = "()") # Tried this with no success

desired <- "Correlation (compare,control)"

>Solution :

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

Try this,

paste0(h, ' (', toString(g), ')')
#[1] "Correlation (compare, control)"

If you don’t want the space in the comma then we can do it manually with paste(), i.e.

paste0(h, ' (', paste(g, collapse = ','), ')')
#[1] "Correlation (compare,control)"
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