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 can I concatenate these strings back together?

I would like to split a string into its elements and then paste them together again. However no matter what I tried, it doesn`t work.

Here are two things I’ve tried:

'hello' %>% strsplit('') %>% paste0()

output: "c(\"h\", \"e\", \"l\", \"l\", \"o\")"

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

'hello' %>% strsplit('') %>% unlist() %>% paste0()

output: "h" "e" "l" "l" "o"

I would simply like to get my ‘hello’ back.

>Solution :

You can use paste but you have to specify the collapse argument.

'hello' %>% strsplit('') %>% unlist() %>% paste(collapse = "")

Alternatively you can use str_c from the stringr library:

'hello' %>% strsplit('') %>% unlist() %>% stringr::str_c(collapse = "")
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