我有以下数据库(宽格式),"st_all",其中有两个变量我希望重塑("P“和"PLC")。主题的id是"g_id“。
g_id study condition sample PLC1 PLC2 PLC3 PLC4 PLC5 PLC6 PLC7 PLC8 PLC9 PLC10 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10
1 1 1 1 1 20 20 20 50 50 20 30 20 50 50 1 2 2 1 2 2 1 1 1 1
2 2 1 1 1 60 70 50 70 60 60 60 70 60 50 1 2 1 1 2 2 1 1 1 1
3 3 1 1 1 80 50 55 58 70 50 80 80 60 65 1 2 2 1 2 2 1 1 1 1
4 4 1 1 1 89 51 59 62 72 60 86 80 61 54 1 1 2 1 2 2 1 1 1 1
5 5 1 1 1 90 50 60 70 80 50 90 80 60 50 1 1 1 1 2 2 1 1 1 1
6 6 1 1 1 95 50 60 100 95 60 50 60 60 55 1 2 2 1 2 2 1 1 1 1为此,我运行了以下代码:
reshape(st_all,
idvar="g_id",
direction="long",
varying=list(c(5:14),c(15:24)),
v.names=c("PLC","P")
)我得到了以下错误:
Error in `row.names<-.data.frame`(`*tmp*`, value = paste(d[, idvar], times[1L], :
invalid 'row.names' length我已经寻找了这个问题的答案,但我没有找到任何答案。
提前谢谢。
发布于 2017-08-12 00:31:31
正如注释中所指出的,当您的数据是tbl时,使用reshape函数将会出现问题。
首先使用as.data.frame:
reshape(as.data.frame(st_all),
idvar = "g_id",
direction = "long",
varying = list(c(5:14), c(15:24)),
v.names = c("PLC","P"))https://stackoverflow.com/questions/34910592
复制相似问题