我有这种格式的数据框:
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))
我想将所有列合并/合并为一个而不保留列名。
示例输出:
text1
text2
text1
text2
text3
text1
text1
text4
我找到了this示例,但它合并了行。
答案 0 :(得分:1)
我们转置数据集,将其连接到vector
并根据该数据创建data.frame
data.frame(newcol = c(t(df)), stringsAsFactors=FALSE)