我想使用 R 重组以下多行 DataFrame,
1 2 3
A Apple Orange Grape
B Car Truck Plane
C House Apartment Garage
进入这个单行 DataFrame。
1_A 2_A 3_A 1_B 2_B 3_B 1_C 2_C 3_C
0 Apple Orange Grape Car Truck Plane House Apartment Garage
感谢您的帮助!
最佳答案
reshape
解决方案,一步处理所有命名和重命名:
reshape(cbind(dat, id=1, time=rownames(dat)),
direction="wide", sep="_", new.row.names=0)[-1]
# 1_A 2_A 3_A 1_B 2_B 3_B 1_C 2_C 3_C
#0 Apple Orange Grape Car Truck Plane House Apartment Garage
关于r - 使用 R 将 DataFrame 展平为单行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69184293/