【发布时间】:2018-02-17 17:49:20
【问题描述】:
这就是我所拥有的:
id<-c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2)
measure<-c("speed","weight","time","speed","weight","time","speed","weight","time",
"speed","weight","time","speed","weight","time","speed","weight","time")
value<-c(1.23,10.3,33,1.44,10.4,31,1.21,10.1,33,4.25,12.5,38,1.74,10.8,31,3.21,10.3,33)
testdf<-data.frame(id,measure,value)
这就是我想要的:
id<-c(1,1,1,2,2,2)
speed<-c(1.23,1.44,1.21,4.25,1.74,3.21)
weight<-c(10.3,10.4,10.1,12.5,10.8,10.3)
time<-c(33,31,33,37,31,33)
res<-data.frame(id,speed,weight,time)
问题在于我的变量速度重量和时间重复。我可以使用带有 if 语句的 for 循环来完成它,但它是一个令人头疼的问题,而且效率不高。这是我在 stackoverflow 上的第一篇文章……长时间的用户第一次提问……谢谢你们!
【问题讨论】:
标签: r reshape data-science reshape2