我想要一种将字符串数组连接成单个字符串的方法。
是否有更基本的方法来连接数组中的值而不是我的' 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
答案 0 :(得分:2)
怎么样:
paste(c(1,2,3), collapse = '')