← Back to R Course | Chapter 6: Strings | Lesson 1 of 7

paste and paste0

In this page:

  1. paste and paste0

paste and paste0

paste() concatenates strings together, inserting a separator (a space by default) between each argument. paste0() is shorthand for paste(..., sep = ""), concatenating with no separator at all. Both also work element-wise on vectors, pairing up corresponding elements.

Note: paste0(a, b) is a common shortcut for building a string with no space, like a file path or identifier.

Example: paste and paste0

markup
first <- "Hello"
second <- "World"

cat(paste(first, second), "\n")
cat(paste0(first, second), "\n")
cat(paste(first, second, sep = "-"), "\n")
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.