Submitted by: Garrett See; Assigned to: Nobody; R-Forge link
The xts package has a last.default method (and a first.default method) that allows for natural language subsetting of dates/times.
e.g.
x <- Sys.time()-1:1000
last(x, '5 minutes')
last(x, '20 seconds')
first(last(x, '5 minutes'), '20 seconds') # first 20 seconds of last 5 minutes
That can be used in the i argument with data.table, but it is not as straightforward/efficient as it might be because it requires converting to either numeric or character and then performing a vector scan
Submitted by: Garrett See; Assigned to: Nobody; R-Forge link
The xts package has a last.default method (and a first.default method) that allows for natural language subsetting of dates/times.
e.g.
That can be used in the i argument with data.table, but it is not as straightforward/efficient as it might be because it requires converting to either numeric or character and then performing a vector scan
Ideally, this would work
But, currently it gives:
Note that calling xts::last on a timeBased vector (i.e. Date, POSIXct, POSIXlt, etc.) returns a vector of the same class