r - data.table: Bypass setkey when using monotonic transform of a key variable -


is 'sorted' attribute part of official data.table api?

i things derive week/month/quarter/year variable date variable, of course monotonic transformation. things using 1 of these monotonically-derived variables.

i'm wondering if safe directly replace date variable name of week/month/etc. variables in sorted attribute , have things work properly? i.e. below safe do:

library(data.table) library(lubridate) dt <- data.table(day=as.date(c('2006-01-30', '2006-01-31', '2006-02-01', '2006-02-02')),                  d=1:4, key='day') dt[, month := floor_date(day, unit='month')] # safe? attr(dt, 'sorted') <- 'month' 

i couldn't figure out if there other underlying data structures reference table might cause problems technique.

yes, use trick time when i'm sure data sorted, use setattr instead avoid copy:

setattr(dt, 'sorted', 'month') 

if @ code of setkeyv you'll see that's - sorts data , sets "sorted" attribute.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -