paste and paste0

paste is a function that converts vector elements to character and then concatenates (links) them.

paste0 is similar to the paste function except its sep argument is "". That means it will concatenate the vectors without any delimiting character (e.g., space, comma, semi-colon).

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 do I paste together two strings?

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

How do I paste together three strings?

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