本文介绍了将dcast与多个value.var一起使用时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我一直在学习如何使用data.table,我在 ?? dcast 上使用了示例,在哪里使用了以下示例

So, I have been learning how to use data.table, I used the example on the ??dcast where is use the following example

dt = data.table(x=sample(5,20,TRUE), y=sample(2,20,TRUE),
                z=sample(letters[1:2], 20,TRUE), d1 = runif(20), d2=1L)

然后

# multiple value.var
dcast(dt, x + y ~ z, fun=sum, value.var=c("d1","d2"))

错误:

这是我的R版本的信息:

here is the information of my R version:

> version
               _
platform       x86_64-w64-mingw32
arch           x86_64
os             mingw32
system         x86_64, mingw32
status
major          3
minor          2.2
year           2015
month          08
day            14
svn rev        69053
language       R
version.string R version 3.2.2 (2015-08-14)
nickname       Fire Safety


推荐答案

I

答案/问题是您需要强制 data.table dcast函数,否则它将使用reshape2功能

The answer/problem is that you need to "force" the data.table dcast function otherwise it will use the reshape2 function

我成功的唯一方法是按以下方式运行dcast:

The only way I was successfull was running dcast as follows:

# multiple value.var
data.table::dcast(dt, x + y ~ z, fun=sum, value.var=c("d1","d2"))

这篇关于将dcast与多个value.var一起使用时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:06