Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upcalculating time difference by group might get the units messed up #3694
Comments
|
Just saw on my stack overflow question that this issue is known. |
|
this is a problem of -.time classes. it picks a unit within each group.
always use difftime when doing grouped time differences and explicitly set
a unit.
I usually wrap it all in as.double.
alternatively, convert your time to integer (or numeric) first and do your
differences on that representation.
quite a common case though, maybe we should add it to the FAQ and/or catch
this particular case & warm or report in verbose.
…On Thu, Jul 11, 2019, 3:40 AM oliver-oliver ***@***.***> wrote:
Just saw on my stack overflow question that this issue is known.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3694?email_source=notifications&email_token=AB2BA5NZJEW5PBSCV7QJPYDP6Y3MBA5CNFSM4H7SQ3P2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZUQQYQ#issuecomment-510199906>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB2BA5NKRC5WTZ2UWL5RCI3P6Y3MBANCNFSM4H7SQ3PQ>
.
|
#Minimal reproducible exampleThe objective is to calculate the time between events grouped by some id. Here is an example:
which results in:
Both columns time_diff_1 and time_diff_2 display the time difference in seconds. However the time_diff_1 which resulted from the grouped calculation mixed up the units. The result for id == 1 is 31 days and one second. It seems as if the units were choosen automatically by group and then gotten overwritten.
To prevent this one can use
difftime(). However I think there is room for improvment, e.g. a warning message when units do not match for different groups.#Output of sessionInfo()