使用重塑包重塑数据库 [英] Reshaping database using reshape package

查看:94
本文介绍了使用重塑包重塑数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重塑数据库的某些行。特别是,我为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?

这篇关于使用重塑包重塑数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆