只论 collapse 这个单词的话,我刚发现下面这个设定,在 paste 函数中,开发者指定用 collapse 参数来设定分隔符,把向量中多个元素拼接成一个长字符串。
data <- data.frame(
id = c(1:2),
col1 = c('春江', '海上'),
col2 = c('潮水', '明月'),
col3 = c('连海平', '共潮生')
)
apply(X = data[, 2:4], MARGIN = 1, FUN = paste)
## [,1] [,2]
## [1,] "春江" "海上"
## [2,] "潮水" "明月"
## [3,] "连海平" "共潮生"
apply(X = data[, 2:4], MARGIN = 1, FUN = paste, collapse = "")
## [1] "春江潮水连海平" "海上明月共潮生"