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

grouped diff returns incorrect results for POSIXct objects #2754

Closed
MichaelChirico opened this issue Apr 16, 2018 · 1 comment
Closed

grouped diff returns incorrect results for POSIXct objects #2754

MichaelChirico opened this issue Apr 16, 2018 · 1 comment

Comments

@MichaelChirico
Copy link
Member

library(data.table)
DT = data.table(
  a = c(1, 1, 2, 2),
  b = structure(
    c(0, 10, 0, 100000000), 
    class = c('POSIXct', 'POSIXt')
  )
)
DT[ , diff(b), keyby = a]
#    a            V1
# 1: 1   10.000 secs
# 2: 2 1157.407 secs

The problem is that diff.POSIXt silently invokes -.POSIXt, which chooses units automatically given its inputs.

These units are ignore on group wrapup:

DT[ , {
  x = diff(b)
  dput(x)
  x
}, keyby = a]
# structure(10, units = "secs", class = "difftime")
# structure(1157.40740740741, units = "days", class = "difftime")
#    a            V1
# 1: 1   10.000 secs
# 2: 2 1157.407 secs

I suppose this is closely related with #995 and is almost identical to #761

@MichaelChirico
Copy link
Member Author

Hmm actually duplicate of #761.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant