我想要一种将字符串数组连接成单个字符串的方法。
是否有比下面的“paste.c”函数更基本的方法来连接数组中的值?
paste(1,2,3) # result: "1 2 3"
paste(c(1,2,3)) # result: "1" "2" "3", analogous to Unix 'paste' result
paste.c <- function(y) {
as.character(
tapply( X = y,
INDEX = rep.int(1, length(y)),
FUN = paste,
sep = "",
collapse = ""
)
)
}
paste.c(c(1,2,3)) # result: "123", which is what I need at the moment
最佳答案
怎么样:
paste(c(1,2,3), collapse = '')
关于R 简单等价于 strcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41042751/