我已经浏览了其他人发布的关于将数据框从宽变长的示例。
我的原始数据框具有以下列
Country,Trial_ID,Trial_name,seed.zone, Prov_name,Alt_min,Alt_max,Prov_ID,Replication, Tree_id Plot_id DBH_05, DBH_06, DBH_09, DBH_10, DBH_11, DBH_13, DBH_14, DBH_15, DBH_17, DBH_18, DBH_20, DBH_21, DBH_23, DBH_24, DBH_25, DBH_27, DBH_29, DBH_30, DBH_31, DBH_34, DBH_35, DBH_37
我想将我的数据框重塑为以下列
Country,Trial_ID,Trial_name,seed.zone, Prov_name,Alt_min,Alt_max,Prov_ID , DBH, Age
library(reshape2)
mydata <- reshape(Database_Final,
idvar=c("Trial_name","Country", "Trial_ID",
"Trial_name","seed zone","Prov_name",
" Alt_min", "Alt_max","Prov_ID","Replication","Tree_id","Plot_id"),
varying = list( "DBH05","DBH06","DBH09","DBH10","DBH11","DBH13","DBH14",
"DBH15","DBH17","DBH18","DBH20","DBH21","DBH23",
"DBH24","DBH25","DBH27","DBH_29","DBH30","DBH31","DBH34","DBH35","DBH_37"),
v.names = "DBH",
timevar = "Age",
times = c( "DBH05","DBH06","DBH09","DBH10","DBH11","DBH13","DBH14",
"DBH15","DBH17","DBH18","DBH20","DBH21","DBH23",
"DBH24","DBH25","DBH27","DBH_29","DBH30","DBH31","DBH34","DBH35","DBH_37"),
direction = "long")
但我不断收到错误:Error in reshapeLong(data, idvar = idvar, timevar = timevar, varying = varying, : 'times' is wrong length