Repository navigation
Support for on-the-fly columns in on #1639
Description
Activity
looks like a duplicate of #625
Big vote for this enhancement since it makes the syntax of data.table shorter, more intuitive and more SQL alike.
Reacted by Uwe Block and Marc-Aurèle RivièreWhen done, update:
http://stackoverflow.com/q/37978658/559784
and
https://stackoverflow.com/q/48282827/559784Because Arun started a list with SO posts which may be updated, I thought it I could add some more I stumbled over:
How to merge dataframes of unequal length based on time with buffer intervals in R?
Data.Table non-equi join with arithmetic operations
subset data.frame base on a time interval + or - list of dates
To update: https://stackoverflow.com/q/52901099
To update: https://stackoverflow.com/q/53559119/2204410
(or close as a duplicate with one of the links above)What would the API be? The difficult part is that users may want to use the newly created
oncondition. The evaluation would be easier if we could get users to use a helper function if they want to access the new column inj.dt[dt, on = .(date >= list(past_date = date-2), date <= date), allow.cartesian = TRUE]The alternative would be like SQL and have the eval happen twice, once in
onand then have users repeat injdt[dt, on = .(date >= date-2, date<=date), .(x.date, past_date = i.date - 2), allow.cartesian = TRUE]Reacted by Uwe Block- addedjoinsUse label:"non-equi joins" for rolling, overlapping, and non-equi joinsUse label:"non-equi joins" for rolling, overlapping, and non-equi joins
on Apr 6, 2020 - addedtop requestOne of our most-requested issuesOne of our most-requested issuesand removed
on Jun 7, 2020 AFAIR
bmergealready doshallowcopies of data, so adding new columns there would be probably easiest way to achieve that. We just need a proper handling foris.callof LHS and RHS of each element ofonargument using internal.parse_on, and then using that inbmerge. The most tricky part can be handling column names well. Eventually we could allow computed columns to be named, the same as we allow inbyargument:.(date2 = date >= date-2, date<=date).
The ability to create columns in
onon-the-fly, like we can injorby, would be appreciated.As a usage example, this would have simplified my answer to the following self-join / moving-average-type answer:
http://stackoverflow.com/a/36534824/3576984
Reproduced here:
Would have been prettier / easier to parse as: