# [R] Calculating date difference in days

reichm@@j m@iii@g oii sbcgiob@i@@et reichm@@j m@iii@g oii sbcgiob@i@@et
Wed May 22 23:43:42 CEST 2019

```R Help

I have a function to calculate a date difference in days but my results come
back in hours.  I suspect I am using the as.POSIXlt function incorrectly .

Suggestions?

# Start time of data to be considered
start_day <- "2016-04-30"

# Make event and sequence IDs into factors
elapsed_days <- function(end_date, start_date){
ed <- as.POSIXlt(end_date)
sd <- as.POSIXlt(start_date)
ed-sd
}

trans_sequence\$eventID <- elapsed_days(trans_sequence\$Date, start_day)

> trans_sequence
# A tibble: 39 x 5
# Groups:   Emitter [15]
Emitter Date        SIZE Geohash
eventID
<int> <date>     <int> <chr>
<time>
1       1 2016-05-01    12 A;B;C;D;E;F;G;H;I;J;K;L
19 hours
2       1 2016-05-02     5 A;B;C;D;E
43 hours
3       1 2016-05-05    11 A;B;C;D;E;F;G;H;I;J;K
115 hours
4       2 2016-05-01     9 C;D;E;F;G;H;I;J;K
19 hours
5       2 2016-05-02     3 F;G;H
43 hours
6       2 2016-05-05     3 L;M;N
115 hours
7       3 2016-05-01     3 L;M;N
19 hours
8       3 2016-05-02     3 I;J;K
43 hours
9       3 2016-05-04    25
A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y  91 hours
10       3 2016-05-05     7 O;P;Q;R;S;T;U
115 hours

Jeff Reichman

[[alternative HTML version deleted]]

```