是否可以将存储在 N*1 矩阵中的单词转换为 R 中的单个句子?

Is it possible to convert words stored in a matrix of N*1 into single sentence in R?

我有一个 1196*1 的矩阵,每一行包含一个单词。我需要把这些词写成一个句子。

I  
Have  
A  
Matrix 

目标:I Have A Matrix.

我们可以使用paste

paste(df1$col, collapse=" ")

如果是matrix,使用

paste(df1[, "col"], collapse=" ")

这是您的矩阵作为可重现的示例:

my_matrix = matrix(c("I", "Have", "A", "Matrix"), ncol = 1)

这里有一个造句的方法:

> paste(my_matrix, collapse = " ")
[1] "I Have A Matrix"