rmergepaste

R: Paste two strings without space


I want to merge following two strings in R (and remove the spaces). I was using paste but I was not able to get desired results.

a <- "big earth"
b <- "small moon"

c <- paste(a,b, sep = "")

I want to have a c <- "bigearthsmallmoon" Thank you very much for the help.


Solution

  • You can paste the strings together into one with paste(). Then you can use gsub() to remove all spaces:

    gsub(" ", "", paste(a, b))
    # [1] "bigearthsmallmoon"