-3

I was working with the paste command in R, when I found that

a <- c("something", "to", "paste")  
paste(a, sep="_") 

produces the output

# [1] "something" "to" "paste"

Which is same as when I print "a"

# [1] "something" "to" "paste"

So what effect does the sep have on the paste command in R?

A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213

1 Answers1

4

sep is more generally applicable when you have more than two vectors of length greater than 1. If you were looking to get "something_to_paste", then you would be looking for the collapse argument.

Try the following to get a sense of what the sep argument does:

paste(a, 1:3, sep = "_")
# [1] "something_1" "to_2"        "paste_3"    

and compare it to collapse:

paste(a, collapse = "_")
# [1] "something_to_paste"
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485