spatsoc
spatsoc copied to clipboard
odd time handling in group_times
group_times can't group odd time thresholds e.g. 2 hour threshold when times are 1am, 3am, 5am... 11pm.
This is because group_times considers the threshold in the context of 24 hours, and a two hour threshold would then group times to 0, 2, 4, 6...
Is there a way around this? Provide an 'offset' argument? Or just make sure it is clear in the vignettes and documentation?
A current workaround is using threshold = '1 hour' which will at least group to 0,1,2,3, ...
this seems to be the problem of the data I'm working with (fixes collected every two hours at uneven hours). Is setting the threshold = '5 minutes' is not enough in this case? If the "sliding window" of 5 minutes starts at midnight and scans the time series, it should capture fixes aggregated both at even and uneven hours, isn't that so? Thanks, Tomasz
Setting the threshold to '5 minutes' is sufficient when working with fixes collected on uneven hours. (Though see #5 for a recent bug fix).
For example:
DT <- data.table(
idate = as.IDate('2018-12-12'),
itime = as.ITime(
c('01:00', '01:02', '01:01',
'03:00', '03:02', '03:00',
'05:00', '05:01', '05:01')
)
)
group_times(DT, c('idate', 'itime'), threshold = '5 minutes')
| idate | itime | minutes | timegroup |
|---|---|---|---|
| 2018-12-12 | 01:00:00 | 0 | 1 |
| 2018-12-12 | 01:02:00 | 0 | 1 |
| 2018-12-12 | 01:01:00 | 0 | 1 |
| 2018-12-12 | 03:00:00 | 0 | 2 |
| 2018-12-12 | 03:02:00 | 0 | 2 |
| 2018-12-12 | 03:00:00 | 0 | 2 |
| 2018-12-12 | 05:00:00 | 0 | 3 |
| 2018-12-12 | 05:01:00 | 0 | 3 |
| 2018-12-12 | 05:01:00 | 0 | 3 |
This issue is concerned with the (possibly rare?) instance where one might want to group on uneven 2 hour fixes, with a 2 hour threshold. Not sure when one might want this, but right now - it isn't possible.
For example, this data with 2 hour fixes, on the odd hours, with the nearest hour being detected is even.
DT <- data.table(
idate = as.IDate('2018-12-12'),
itime = as.ITime(
c('01:00', '01:02', '00:58',
'03:00', '03:02', '02:59',
'05:00', '05:01', '04:58')
)
)
group_times(DT, c('idate', 'itime'), threshold = '2 hours')
| idate | itime | hours | timegroup |
|---|---|---|---|
| 2018-12-12 | 01:00:00 | 2 | 1 |
| 2018-12-12 | 01:02:00 | 2 | 1 |
| 2018-12-12 | 00:58:00 | 0 | 2 |
| 2018-12-12 | 03:00:00 | 4 | 3 |
| 2018-12-12 | 03:02:00 | 4 | 3 |
| 2018-12-12 | 02:59:00 | 2 | 1 |
| 2018-12-12 | 05:00:00 | 6 | 4 |
| 2018-12-12 | 05:01:00 | 6 | 4 |
| 2018-12-12 | 04:58:00 | 4 | 3 |