r - 如何在R中将两列合并为一列?
问题描述
我有一张有 3 列的表
A B C
1 2 3
2 4 5
3 3 6
我一直在尝试将列合并为一列。
输出应该是
x
1
2
3
2
4
3
3
5
6
解决方案
你可以使用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
或转换为矩阵:
data.frame(x = c(as.matrix(df)), row.names = NULL)
数据
df <- structure(list(A = 1:3, B = c(2L, 4L, 3L), C = c(3L, 5L, 6L)),
class = "data.frame", row.names = c(NA, -3L))
推荐阅读
- eclipse - 三元组的树状视图并删除 URI
- d3.js - 函数 mousemove 代码在 d3.js 堆叠条形图中不起作用
- c++11 - 如何在复合设计模式中动态选择运算符 [ ] 的返回类型?
- ios - iOS Swift 4 重启导航控制器
- rust-cargo - 货物登记目录
- excel - 每次将公式中的数字加 2
- android - 无法使用 AndroidViewModel 超类和 Room 获取数据库的实例
- php - 如何根据其输入显示小数位数?
- amazon-web-services - 将 dockerfile 部署到 AWS Fargate(在 AWS 上构建 docker 映像)
- global-variables - 我想在创建日期搜索变量后进行新的变量搜索,但使用搜索日期中的搜索结果