2016-01-20 41 views
1

我有以下數據庫(廣泛形式),「st_all」,其中我有兩個變量我希望重塑(「P」和「PLC」)。主題的ID是「g_id」。reshape錯誤 - 無效'row.names'長度

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 

...我已經尋找一個答案,但我不找到任何。

在此先感謝。

+0

您的代碼對我的作品 –

+1

我找到了答案。我正在使用tbl格式,並影響重塑功能。 –

回答

2

正如評論中指出的那樣,當您的數據爲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")) 
相關問題