paste and paste0

Basics

paste is a function that converts vector elements to character strings and then concatenates them. It has a sep argument (default sep = " ") where the user can include a phrase/string to separate the strings being pasted together

paste0 is a version of paste where its sep argument is "", meaning the strings will be linked with no characters in between.


Examples

How do I concatenate two vectors, element-wise, with a comma in between values from each vector?

Click to see solution
vector1 <- c("one", "three", "five")
vector2 <- c("two", "four", "six")
paste(vector1, vector2, sep=",")
[1] "one,two"    "three,four" "five,six"

How can I paste together two strings with no separation?

Click to see solution
paste0("abra", "kadabra")
[1] "abrakadabra"

How do I paste together three strings with no separation?

Click to see solution
paste0("abra", "kadabra", "alakazam")
[1] "abrakadabraalakazam"