R tip #1: use paste0 instead of paste

You expect that concatenating two strings will yield the strings “mashed together”. But paste is annoying (or convenient) in that it adds a separator by default (space). paste0 doesn’t do this, so it acts more like conventional concatenation which is simply more convenient, usually. So I advocate for the oddly named paste0 to be your default paste.

An example:

paste("var","First")

Output:
[1] "var First"

paste0("var","First")
Output:
[1] "varFirst"
 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s