I have a data frame of summary statistics, which I convert to wide using reshape. This works fine. However, if I convert the table to a data.table in between (to add a another column with a test statistic), reshape throws an error, even if I do not change the data.
我有一个汇总统计数据的数据框架,我将其转换为宽格式。这是很好。但是,如果我将表转换为数据。中间的表(添加带有测试统计信息的另一列),重新创建将抛出一个错误,即使我没有更改数据。
require(data.table)
stats <- structure(list(sample = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("panel.1yr", "panel.2yr", "panel.3yr", "panel.inc", "pre.inc", "pre.prev", "post.inc", "post.prev"), class = "factor"), base = c(2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002), ref = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("2004", "2002-2004", "2001", "2000", "2009", "2008"), class = "factor"), var = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("distance", "time"), class = "factor"), treated = c(0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1), distance = c(10000, 30000, 50000, 1e+05, 10000, 30000, 50000, 1e+05, 10000, 30000, 50000, 1e+05, 10000, 30000, 50000, 1e+05), all = c(602L, 6357L, 8528L, 9272L, 435L, 2438L, 3456L, 6360L, 245L, 2693L, 3699L, 4084L, 187L, 983L, 1400L, 2660L), di.recip = c(5L, 39L, 57L, 62L, 4L, 16L, 22L, 45L, 2L, 25L, 36L, 37L, 1L, 11L, 16L, 35L), irr = c(0.00830564784053156, 0.00613496932515337, 0.00668386491557223, 0.00668679896462468, 0.00919540229885057, 0.00656275635767022, 0.00636574074074074, 0.00707547169811321, 0.00816326530612245, 0.00928332714444857, 0.0097323600973236, 0.00905974534769833, 0.0053475935828877, 0.0111902339776195, 0.0114285714285714, 0.0131578947368421)), .Names = c("sample", "base", "ref", "var", "treated", "distance", "all", "di.recip", "irr"), row.names = c(NA, 16L), class = "data.frame")
stats <- data.table(stats)
stats.wide <- reshape(stats, v.names = c("all", "di.recip", "irr", "irr.prom"),
timevar = "treated", idvar = c("sample", "var", "distance"),
direction = "wide" )
This produces the following error:
这会产生以下错误:
Error in tapply(a, as.vector(tmp), function(b) length(unique(b)) == 1L) :
arguments must have same length
but runs fine when the data.table line is commented out.
但当数据显示时,运行良好。表行注释掉了。
1 个解决方案
#1
3
Thanks. Please raise a bug report for it :
谢谢。请提出错误报告:
bug.report(package="data.table")
EDIT: Bug #1794 now fixed in v1.8.0. Thank you.
编辑:错误#1794现在修正在v1.8.0中。谢谢你!
#1
3
Thanks. Please raise a bug report for it :
谢谢。请提出错误报告:
bug.report(package="data.table")
EDIT: Bug #1794 now fixed in v1.8.0. Thank you.
编辑:错误#1794现在修正在v1.8.0中。谢谢你!