Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group_times misses nearest hour with mins threshold #5

Closed
robitalec opened this issue Dec 12, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@robitalec
Copy link
Member

commented Dec 12, 2018

If group_times threshold is minutes (e.g. 5 minutes), we aren't grouping to the nearest hour if we are nearer to next hour than e.g. 55 minutes.

Example:

  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 = '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 00:58:00 60 2
2018-12-12 03:00:00 0 3
2018-12-12 03:02:00 0 3
2018-12-12 02:59:00 60 4
2018-12-12 05:00:00 0 5
2018-12-12 05:01:00 0 5
2018-12-12 04:58:00 60 6

We'd expect here to have 3 timegroups (on 1:00, 3:00 and 5:00).
We end up with 6.

Note: this kind of rolling to the nearest hour was addressed for the less frequent, rolling 24 hours to the next day.

Regardless, still miss grouping row 3 and row 9.

DT <- data.table(
  idate = as.IDate(
    c('2018-12-12','2018-12-12', '2018-12-12',
      '2018-12-12','2018-12-12', '2018-12-13',
      '2018-12-13','2018-12-13', '2018-12-13')),
    itime = as.ITime(
      c('22:00', '22:02', '21:58',
        '23:58', '23:59', '0:01',
        '2:00', '2:01', '1:58'))
)
  
group_times(DT, c('idate', 'itime'), threshold = '5 minutes')
idate itime minutes timegroup
2018-12-12 22:00:00 0 1
2018-12-12 22:02:00 0 1
2018-12-12 21:58:00 60 2
2018-12-12 23:58:00 60 3
2018-12-12 23:59:00 60 3
2018-12-13 00:01:00 0 3
2018-12-13 02:00:00 0 4
2018-12-13 02:01:00 0 4
2018-12-13 01:58:00 60 5

@robitalec robitalec self-assigned this Dec 12, 2018

@robitalec robitalec closed this in #6 Dec 12, 2018

robitalec added a commit that referenced this issue Dec 12, 2018

Merge pull request #6 from ropensci/bug/nearest-hr-with-mins
group_times misses nearest hour with mins threshold (fixes #5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.