简体   繁体   English

如何在 R 中将两列合并为一列?

[英]How to combine two columns into one in R?

I have one table with 3 columns我有一张有 3 列的表

A      B     C
1      2     3
2      4     5
3      3     6

I have been trying to combine columns into one column.我一直在尝试将列合并为一列。

The output should be output 应该是

x
1
2
3
2
4
3
3
5
6

You could use unlist :您可以使用unlist

data.frame(x = unlist(df), row.names = NULL)

#  x
#1 1
#2 2
#3 3
#4 2
#5 4
#6 3
#7 3
#8 5
#9 6

Or convert to matrix:或转换为矩阵:

data.frame(x = c(as.matrix(df)), row.names = NULL) 

data数据

df <- structure(list(A = 1:3, B = c(2L, 4L, 3L), C = c(3L, 5L, 6L)), 
class = "data.frame", row.names = c(NA, -3L))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM