Skip to content

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

Closed

Description

@DavidArenburg
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))

Activity

  1. arunsrinivasan commented on Feb 9, 2015

    @arunsrinivasan
    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.

  2. added this to the v1.9.6 milestone on Mar 6, 2015
  3. mrdwab commented on Apr 30, 2015

    @mrdwab

    @arunsrinivasan There was this. :-)

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions