使用重塑包重塑数据库

问题描述:

我想重塑数据库的某些行。特别是,我为Id列复制了一些行。我想将这一行转换为列。我提供的代码代表了我的数据库示例。
我正在尝试使用t()并重塑形状,但我不会那样做。有人可以给我任何建议吗?

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))


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?