1

我回到了我上个月写的一些 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
4

1 回答 1

2

reshape 和 reshape2 版本的文档都说:

如果您都不提供,melt 将假定因子和字符变量是 id 变量,而所有其他变量都是测量的。

melt记录的行为也是如此。

于 2012-12-12T19:54:38.167 回答