我感觉我遗漏了一些基本的东西,却无法弄明白。
尝试融化数据集并重新制作原始形式,但它不起作用。
library(reshape2)
df <- structure(list(measure1 = c(4.11000246380076, 4.29087381534614,
4.30709021582289), measure2 = c(1.71250102658365, 1.78786408972756,
1.79462092325954), measure3 = c(86.3932114427626, 84.6768654385354,
86.9635134280892)), .Names = c("measure1", "measure2", "measure3"
), row.names = c(NA, 3L), class = "data.frame")
原始数据集:
measure1 measure2 measure3
1 4.110002 1.712501 86.39321
2 4.290874 1.787864 84.67687
3 4.307090 1.794621 86.96351
Molten数据集:
df <- melt(df)
variable value
1 measure1 4.110002
2 measure1 4.290874
3 measure1 4.307090
4 measure2 1.712501
5 measure2 1.787864
6 measure2 1.794621
7 measure3 86.393211
8 measure3 84.676865
9 measure3 86.963513
尝试重铸成原始形状,但输出很奇怪:
df <- dcast(df, value ~ variable)
value measure1 measure2 measure3
1 1.712501 NA 1.712501 NA
2 1.787864 NA 1.787864 NA
3 1.794621 NA 1.794621 NA
4 4.110002 4.110002 NA NA
5 4.290874 4.290874 NA NA
6 4.307090 4.307090 NA NA
7 84.676865 NA NA 84.67687
8 86.393211 NA NA 86.39321
9 86.963513 NA NA 86.96351
我错过了什么?