R 编程中没有分隔符的元素串联 - paste0()函数
R 语言中的paste0()
函数用于连接所有元素而无需分隔符。
Syntax: paste0(…, collapse = NULL)
Parameters:
…: one or more R objects, to be converted to character vectors.
collapse: an optional character string to separate the results.
示例 1:
# R program to illustrate
# paste0 function
# Calling paste0() function
paste0("GFG", "gfg")
paste0("GFG", " gfg")
paste0(letters[1:4])
输出 :
[1] "GFGgfg"
[1] "GFG gfg"
[1] "a" "b" "c" "d"
示例 2:
# R program to illustrate
# paste0 function
# Calling paste0() function
paste0(letters[1:6], collapse ="-")
paste0("G", 1:5)
输出:
[1] "a-b-c-d-e-f"
[1] "G1" "G2" "G3" "G4" "G5"