Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dcast.data.table Error #1974

Closed
Ping2016 opened this issue Dec 26, 2016 · 2 comments · Fixed by #3384
Closed

dcast.data.table Error #1974

Ping2016 opened this issue Dec 26, 2016 · 2 comments · Fixed by #3384
Labels

Comments

@Ping2016
Copy link

@Ping2016 Ping2016 commented Dec 26, 2016

I am using data.table 1.10.0

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)
dcast.data.table(dt, x + y ~ z, fun.aggregate=list(sum, mean), value.var=list("d1", "d2"))
It can work well.

x y d1_sum_a d1_sum_b d2_mean_a d2_mean_b
1: 1 1 0.57820795 0.000000 1 NaN
2: 1 2 0.57323882 1.030819 1 1
3: 2 2 0.50448265 2.236394 1 1
4: 3 1 0.04189855 1.010506 1 1
5: 3 2 0.94923490 0.000000 1 NaN
6: 4 1 0.44673494 1.112272 1 1
7: 5 1 0.91163728 0.000000 1 NaN
8: 5 2 0.60146531 0.000000 1 NaN

I am trying to do like this:
fun.list <- list(sum, mean)
value.list <- list("d1", "d2")
dcast.data.table(dt, x + y ~ z, fun.aggregate=fun.list, value.var=value.list)

Error occurs:

Error in aggregate_funs(fun.call, lvals, sep, ...) :
When 'fun.aggregate' and 'value.var' are both lists, 'value.var' must be either of length =1 or =length(fun.aggregate).

But length(fun.list) is eque to length(value.list).
length(fun.list)

[1] 2

length(value.list)

[1] 2

@jdthorpe
Copy link

@jdthorpe jdthorpe commented Oct 28, 2017

If you're having this issue because you're calling dcast within your own function, there is a partial solution here.

@arunsrinivasan
Copy link
Member

@arunsrinivasan arunsrinivasan commented Feb 9, 2019

duplicate of #2949

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants