The ability to create columns in on on-the-fly, like we can in j or by, 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:
require(data.table)
date <- as.Date(c('2012-01-01','2012-01-01','2012-01-01',
'2012-01-02','2012-01-02','2012-01-03',
'2012-01-04','2012-01-05','2012-01-05',
'2012-01-06','2012-01-06','2012-01-06'))
email <- c('test@test.com', 'test1@test.com','test2@test.com',
'test1@test.com', 'test2@test.com','test@test.com',
'test@test.com','test@test.com','test@test.com',
'test@test.com','test@test.com','test1@test.com')
dt <- data.table(date, email)
dt[dt[ , .(date3=date, date2 = date - 2, email)],
on = .(date >= date2, date<=date3),
allow.cartesian = TRUE
][ , .(count = uniqueN(email)),
by = .(date = date + 2)]
Would have been prettier / easier to parse as:
dt[dt, on = .(date >= date-2, date<=date), allow.cartesian = TRUE
][ , .(count = uniqueN(email)), by = 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: