R Func Paste
# R paste() Function - String Concatenation
[ R Language Examples](https://example.com/r/r-examples.html)
The R paste() function is used to concatenate multiple strings or vectors together.
paste0() is a separator-free version of paste(), equivalent to paste(sep = "").
The paste() function syntax is as follows:
paste(..., sep = " ", collapse = NULL) paste0(..., collapse = NULL)
**Parameter Description:**
* **...** Strings or vectors to concatenate.
* **sep** Separator during concatenation, default is a single space.
* **collapse** Further merges the concatenated vector into a single string, using collapse as the separator.
## Examples
# Basic concatenation (default space separator)
result1 <-paste("Hello", "TUTORIAL", "R")
print(result1)
# Specify separator
result2 <-paste("2026", "05", "11", sep ="-")
print(result2)
# paste0 without separator
result3 <- paste0("ID_", 1:5)
print(result3)
# Use collapse to merge vector into a single string
words <-c("R", "is", "powerful")
sentence <-paste(words, collapse =" ")
print(sentence)
Executing the above code outputs:
"Hello TUTORIAL R" "2026-05-11" "ID_1" "ID_2" "ID_3" "ID_4" "ID_5" "R is powerful"
paste() is commonly used to dynamically generate labels or filenames:
## Examples
# Generate month labels
months<-paste("Month", 1:12, sep ="")
print(months[1:5])
# Generate file paths
path <- paste0("data/", c("sales", "inventory", "customers"), ".csv")
print(path)
Executing the above code outputs:
"Month1" "Month2" "Month3" "Month4" "Month5" "data/sales.csv" "data/inventory.csv" "data/customers.csv"
[ R Language Examples](https://example.com/r/r-examples.html)
YouTip