6

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.

Behzod A
  • 173
  • 1
  • 2
  • 14
  • I think you are looking for https://stackoverflow.com/questions/5992082/how-to-remove-all-whitespace-from-a-string – Ronak Shah May 25 '20 at 10:43

2 Answers2

13

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

12

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"
s_baldur
  • 29,441
  • 4
  • 36
  • 69