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

Make dcast.data.table work with undefined variables #1037

Closed
DavidArenburg opened this issue Feb 9, 2015 · 2 comments
Closed

Make dcast.data.table work with undefined variables #1037

DavidArenburg opened this issue Feb 9, 2015 · 2 comments
Assignees
Milestone

Comments

@DavidArenburg
Copy link
Member

library(data.table) ; library(reshape2) 
dcast(df, cumsum(V1 == 0) ~ V1, value.var = 'V2') # Works
#   cumsum(V1 == 0)     0     1     2     3      4
#1               1 1.052 0.542 0.496 0.402 0.2780
#2               2 5.115 4.329 4.121 4.075 4.0088
dcast(setDT(df), cumsum(V1 == 0) ~ V1, value.var = 'V2') # Doesn't work
# Error in dcast.data.table(setDT(df), cumsum(V1 == 0) ~ V1, value.var = "V2") : 
#   Column 'cumsum(V1==0)' not found.

Data set

df <- structure(list(V1 = c(0L, 1L, 2L, 3L, 4L, 0L, 1L, 2L, 3L, 4L), 
          V2 = c(1.052, 0.542, 0.496, 0.402, 0.278, 5.115, 4.329, 4.121, 
          4.075, 4.0088)), .Names = c("V1", "V2"), class = "data.frame", row.names = c(NA, -10L))
@arunsrinivasan
Copy link
Member

The next version of dcast will be able to do this.

I did not know this was even possible with reshape2::dcast. I don't think there are examples showcasing this feature.

@mrdwab
Copy link

mrdwab commented Apr 30, 2015

@arunsrinivasan There was this. :-)

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

No branches or pull requests

3 participants