R - 按行折叠

R - Collapse By Row

我需要按行折叠我的数据

seq = structure(c("h", "d", "s", "s", "f", "k", "s", "s", "f", "d", 
"d", "d", "l", "l", "d", "d"), .Dim = c(4L, 4L), .Dimnames = list(
NULL, c("act1.055", "act1.056", "act1.057", "act1.058")))

我的数据是这样的:

     act1.055 act1.056 act1.057 act1.058
[1,] "h"      "f"      "f"      "l"     
[2,] "d"      "k"      "d"      "l"     
[3,] "s"      "s"      "d"      "d"     
[4,] "s"      "s"      "d"      "d" 

如果我这样做

paste(seq, collapse = "")
[1] "hdssfkssfdddlldd"

这不是我想要的。

我需要的是

hffl
dkdl 
ssdd 
ssdd

尽可能在矩阵中。

matrix(apply(seq, 1, paste, collapse=''), ncol=1)
#     [,1]  
#[1,] "hffl"
#[2,] "dkdl"
#[3,] "ssdd"
#[4,] "ssdd"

另一个选项:

matrix(do.call(paste0, data.frame(seq)))

输出:

     [,1]  
[1,] "hffl"
[2,] "dkdl"
[3,] "ssdd"
[4,] "ssdd"