Skip to content

Difference between paste() and paste0()

Probably, function paste is one of the most used function in R. The objective of this function is concatenate a series of strings.

The arguments of the function are:

= The space to write the series of strings.

sep = The element which separates every term. It should be specified with character string format.

collapse = The element which separates every result. It should be specified with character string format and it is optional. i

We can see an example where both arguments works together:

As we can see in fourth example, if we specify a value in argument collapse, we obtain an unique string instead of five as in the previous example

The difference between paste() and paste0() is that the argument sep by default is ” ” (paste) and “” (paste0).

In conclusion, paste0() is faster than paste() if our objective is concatenate strings without spaces because we don’t have to  specify the argument sep. 

Published inDifference between (Series)R

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *