相关疑难解决方法(0)

更简单的方法将熔化的数据框重建为原始数据框

如何重新创建data.frame我融化的reshape2

可重复的例子

library(reshape2)
library(plyr)
data(iris)
df  <- melt(iris, id.vars="Species")
head(df)
  Species     variable value
1  setosa Sepal.Length   5.1
2  setosa Sepal.Length   4.9
3  setosa Sepal.Length   4.7
4  setosa Sepal.Length   4.6
5  setosa Sepal.Length   5.0
6  setosa Sepal.Length   5.4
# Great, I'd like to get the original iris back
Run Code Online (Sandbox Code Playgroud)

我尝试过的 dcast

  dcast(df, Species~variable, value.var = "value")
    # should work but doesn't
Run Code Online (Sandbox Code Playgroud)

临时解决方案

# This works but clearly it shouldn't be this hard.
ddply(df, .(Species), function(x) {
    Species <- …
Run Code Online (Sandbox Code Playgroud)

r reshape2

6
推荐指数
1
解决办法
663
查看次数

标签 统计

r ×1

reshape2 ×1