将所有列合并为一列而不保留列名

Merge all columns into one without keeping colnames

我有这种格式的数据框:

df <- structure(list(col1 = structure(1:2, .Label = c("text1", "text3"
), class = "factor"), col2 = structure(c(2L, 1L), .Label = c("text1", 
"text2"), class = "factor"), col3 = structure(c(1L, 1L), .Label = "text1", class = "factor"), 
    col4 = structure(1:2, .Label = c("text2", "text4"), class = "factor")), .Names = c("col1", 
"col2", "col3", "col4"), class = "data.frame", row.names = c(NA, 
-2L))

而且我想 merge/combine 将所有列合并为一个而不保留列名。

示例输出:

text1
text2
text1
text2
text3
text1
text1
text4

我找到了 示例,但它合并了行。

我们转置数据集,将其连接到 vector 并基于该

创建一个 data.frame
data.frame(newcol = c(t(df)), stringsAsFactors=FALSE)