【发布时间】:2012-12-12 19:45:09
【问题描述】:
我回到了我上个月编写的一些 R 代码,但我使用的 reshape 版本(0.8.4,R 2.15.2)似乎改变了该功能。
这是一个示例:
> library(reshape)
> so.test <- data.frame(
one = as.character(rnorm(750)),
two = as.character(rnorm(750)),
three = as.character(rnorm(750)), four = as.character(rnorm(750)))
> check <- melt(so.test)
Using one, two, three, four as id variables
这给出了一个与原始数据相同的data.frame:
> table(so.test == check)
TRUE
3000
我也用 reshape2::melt 试过这个,但我得到了相同的结果。有趣的是,melt() 函数可以与带有数值的 data.frame 一起正常工作:
> so.test2 <- data.frame(
one = rnorm(750),
two = rnorm(750),
three = rnorm(750), four = rnorm(750))
> check2 <- melt(so.test2)
Using as id variables
> head(check2)
variable value
1 one 0.2471168
2 one -0.0663480
3 one -0.0251867
4 one 2.8786207
5 one -0.2586785
6 one -0.7508927
【问题讨论】: