小编rm1*_*104的帖子

将行作为单个列放在r中

我有以下data.frame x

a d g
b e h
c f i
Run Code Online (Sandbox Code Playgroud)

注意:以字母为例.实际的data.frame有数字代替字母(实际数据不按升序排列,如本例所示)

我希望通过在第一列中放置2到4列来将其转换为唯一列.预期结果如下

a
b
c
d
e
f
g
h
i
Run Code Online (Sandbox Code Playgroud)

我尝试了以下代码

matrix(t(x), ncol=1, nrow=ncol(x)*nrow(x), byrow=F)
Run Code Online (Sandbox Code Playgroud)

但它(显然)给出了以下内容

a
d 
g
b
e
h
c
f
i
Run Code Online (Sandbox Code Playgroud)

r reshape

6
推荐指数
1
解决办法
4280
查看次数

标签 统计

r ×1

reshape ×1