0Pricing
R Academy · Lesson

Building Strings with paste() and paste0()

Concatenate strings with separators using paste and paste0.

paste() Basics

paste() converts its arguments to character strings and concatenates them with a separator. By default the separator is a single space ' '. It is the most versatile string-building function in base R.

paste('Hello', 'World')
paste('User', 'ID', ':', 42)
paste('R', 'version', '4.3.1')

paste0() — Zero-Separator Shortcut

paste0() is identical to paste(..., sep=''). It concatenates strings with no separator between them. This is the go-to function when building file paths, column names, or URLs programmatically.

paste0('file_', 1:5, '.csv')
paste0('col_', c('a', 'b', 'c'))
paste0('/home/user/', 'data.csv')

All lessons in this course

  1. Building Strings with paste() and paste0()
  2. Formatted Output with sprintf()
  3. Displaying Output with cat() and print()
  4. String Padding and Alignment
← Back to R Academy