Próbuję zrobić prosty reshape
aby test
wyglądać następująco:prosty Reshape w R stosując reshape2 powoduje błąd
a_estimate, a_tstat, b_estimate, b_tstat
1, 3, 2, 4
Jest to kod próbuję:
require(reshape2)
test = data.frame(cf=c("a", "b"), estimate=c(1,2), tstat=c(3,4))
m = melt(test, id.vars="cf")
d = dcast(m, formula = . ~ cf + variable)
Error: nrow(res$labels[[1]]) == nrow(data) is not TRUE
Co się dzieje tutaj?
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] reshape2_1.2.2
loaded via a namespace (and not attached):
[1] plyr_1.8 stringr_0.6.2
Jeśli celem jest odzyskanie '' m' test' z czym chcesz: 'dcast (m, por ~ zmienna, value.var = "value") ' –
@ G.Grothendieck: nie jestem pewien, czy podążam, celem jest sprawienie, żeby test wyglądał jak druga linia pytania. – Alex
Spróbuj tego: 'dcast (m, 1 ~ cf + variable)' –