Reshaping database using reshape package

风格不统一 提交于 2019-12-11 06:07:32

问题


I would like to reshaping some rows of my database. In particular I have some row that it replicate for the Id column. I would like to convert this row in column. I provide a code that it represent a example of my database. I'm trying with t() and reshape but it doesn't do that I would. Can anyone give me any suggestions?

test<-data.frame(Id=c(1,1,2,3),
    St=c(20,80,80,20),
    gap=seq(0.02,0.08,by=0.02),
    gip=c(0.23,0.60,0.86,2.09),
    gat=c(0.0107,0.989,0.337,0.663))

回答1:


setNames(data.frame(t(test))[2:nrow(data.frame(t(test))),], test$Id)

          1      1      2      3
St  20.0000 80.000 80.000 20.000
gap  0.0200  0.040  0.060  0.080
gip  0.2300  0.600  0.860  2.090
gat  0.0107  0.989  0.337  0.663

It helps to provide an expected output. It this what you expected?



来源:https://stackoverflow.com/questions/56394091/reshaping-database-using-reshape-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!