Error using dcast with multiple values. Var

So, I was learning how to use data.table, I used an example in ??dcastwhere the following example is used

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) 

then

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

and I get the error:

Error in .subset2 (x, i, exact = exact): index outside In addition: Warning: In if (! (.Var% value in% of names (data))) {: the
condition has a length> 1, and will be used only the first element

here is the information about my version of R:

> 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
+2
source share
1 answer

I came across the same thing and it was unpleasant as hell.

/ , "" data.table dcast, reshape2

, , - dcast :

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

All Articles