reshape error - invalid 'row.names' length

℡╲_俬逩灬. 提交于 2019-12-10 18:57:18

问题


I have the following database (in wide form), "st_all", where I have got two variables I wish to reshape ("P" and "PLC"). The id for the subjects is "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

To do so I ran the following code:

reshape(st_all,
idvar="g_id",
direction="long",
varying=list(c(5:14),c(15:24)), 
v.names=c("PLC","P")
)

and I get the following error:

Error in `row.names<-.data.frame`(`*tmp*`, value = paste(d[, idvar], times[1L],  : 
invalid 'row.names' length

I have searched for an answer to this, but I do not find any.

Thanks in advance.


回答1:


As noted in the comments, you'll have problems with the reshape function when your data is a tbl.

Use as.data.frame first:

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/reshape-error-invalid-row-names-length

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!