1
我試圖使用Reshape2庫融化R中我的數據幀,使用此功能:熔化數據幀
mtable <- melt(df, id = "type")
print(mtable)
,但我得到一個錯誤說:Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, dims [product 3] do not match the length of object [24]
。數據幀如下所示:
+---+--------+----------+----------+----------+----------+----------+----------+----------+----------+
| | type | x150 | x250 | x300 | x350 | x450 | x575 | x675 | x800 |
+---+--------+----------+----------+----------+----------+----------+----------+----------+----------+
| 1 | Long | 1.882222 | 1.129333 | 0.941111 | 0.806667 | 0.627407 | 0.491014 | 0.418272 | 0.352917 |
+---+--------+----------+----------+----------+----------+----------+----------+----------+----------+
| 2 | Middle | 1.44 | 0.864 | 0.72 | 0.617143 | 0.48 | 0.375652 | 0.32 | 0.27 |
+---+--------+----------+----------+----------+----------+----------+----------+----------+----------+
| 3 | Short | 1.0975 | 0.6585 | 0.54875 | 0.470357 | 0.365833 | 0.286304 | 0.243889 | 0.205781 |
+---+--------+----------+----------+----------+----------+----------+----------+----------+----------+
錯誤的含義是什麼,以及如何將數據幀從寬轉換爲長格式?
的dput(head(df))
輸出:
structure(list(type = structure(c(3L, 2L, 1L), .Label = c("bottom",
"middle", "top"), class = "factor"), x150 = structure(c(1.88222222222222,
1.44, 1.0975), .Dim = 3L), x250 = structure(c(1.12933333333333,
0.864, 0.6585), .Dim = 3L), x300 = structure(c(0.941111111111111,
0.72, 0.54875), .Dim = 3L), x350 = structure(c(0.806666666666667,
0.617142857142857, 0.470357142857143), .Dim = 3L), x450 = structure(c(0.627407407407407,
0.48, 0.365833333333333), .Dim = 3L), x575 = structure(c(0.491014492753623,
0.375652173913043, 0.286304347826087), .Dim = 3L), x675 = structure(c(0.418271604938272,
0.32, 0.243888888888889), .Dim = 3L), x800 = structure(c(0.352916666666667,
0.27, 0.20578125), .Dim = 3L)), .Names = c("type", "x150", "x250",
"x300", "x350", "x450", "x575", "x675", "x800"), row.names = c("0",
"1", "2"), class = "data.frame")
你可以發佈'dput(head(df))'的輸出嗎?變量的結構可能存在問題 –
將其添加到問題中。 – OleVik