【发布时间】:2012-12-16 10:12:09
【问题描述】:
我有数据集:
top100_repository_name month monthly_increase monthly_begin_at monthly_end_with
Bukkit 2012-03 9 431 440
Bukkit 2012-04 19 438 457
Bukkit 2012-05 19 455 474
CodeIgniter 2012-03 15 492 507
CodeIgniter 2012-04 50 506 556
CodeIgniter 2012-05 19 555 574
我使用以下 R 代码:
library(reshape)
latent.growth.data <- read.csv(file = "LGC_data.csv", header = TRUE)
melt(latent.growth.data, id = c("top100_repository_name", "month"), measured = c("monthly_end_with"))
cast(latent.growth.data, top100_repository_name + month ~ monthly_end_with)
我想用它来创建具有以下结构的数据集:
top100_repository_name 2012-03 2012-04 2012-05
Bukkit 440 457 474
CodeIgniter 507 556 574
但是,当我运行我的代码时,我得到以下输出:
Using monthly_end_with as value column. Use the value argument to cast to override this choice
Error in `[.data.frame`(data, , variables, drop = FALSE) :
undefined columns selected
如何修改我的代码以生成所需的输出?
【问题讨论】:
-
我很确定我的编辑是正确的,但请验证。
-
您需要做几件事:(i) 将融化的结果保存到一个对象中,比如
latent.growth.melt,然后按照下面的在latent.growth.melt上运行演员表。如果您使用更新的 reshape2 包(推荐),则使用 dcast() 而不是 cast() - 最后一行应该类似于dcast(latent.growth.melt, top100_repository_name ~ month, value.var = "value")。您可以通过查看latent.growth.melt来了解原因。
标签: r reshape data-manipulation