4

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
  • 119
  • 1
  • 2
  • 12
  • 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

9

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"
sindri_baldur
  • 25,109
  • 3
  • 30
  • 57
2

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

Qian Chen
  • 14,824
  • 18
  • 61
  • 88