0

I'm trying to find the time interval of a site visit

I formated the time date columns as following:

as.POSIXct( StartedDateTime,  format = "%d/%m/%Y %H:%M")
as.POSIXct( EndDateTime,  format = "%d/%m/%Y %H:%M")

Data Sample:

VisitID <- c"1015799589" "1015808075" "1015814910" "1015816258"
 "1015823399" "1015825771" "1015826824" "1015830050"
 "1015838465" "1015840018" "1015842349" "1015843419"
 StartedDateTime <- c"2019-11-27 22:02:00 GMT" "2019-11-27 19:36:00 GMT" "2019-11-28 08:33:00 GMT"
"2019-11-27 19:49:00 GMT" "2019-11-27 22:56:00 GMT" "2019-11-27 16:28:00 GMT"
"2019-07-04 09:48:00 BST" "2019-07-03 08:20:00 BST" "2019-07-02 02:57:00 BST"
"2019-07-02 02:28:00 BST" "2019-07-02 08:46:00 BST" "2019-07-02 04:22:00 BST"
EndDateTime <- c"2019-12-02 16:52:00 GMT" "2019-12-19 08:00:00 GMT" "2019-04-02 13:11:00 BST"
 "2019-04-09 09:59:00 BST" "2019-12-04 09:00:00 GMT" "2019-12-04 09:00:00 GMT"
 "2019-12-04 09:00:00 GMT" "2019-04-02 17:00:00 BST" "2019-04-02 17:00:00 BST"
 "2019-04-12 14:00:00 BST" "2019-04-12 14:00:00 BST" "2019-04-03 08:00:00 BST"

I tried to find the time interval (some visits will last for more than two days

VisitDuration<- difftime(EndDateTime, StartDateTime, units= "secs") 

then

seconds_to_period(VisitDuration) 
VisitDuration
 "18d 12H 18M 0S"  "8d 6H 27M 0S"   
 "4d 4H 43M 0S"    "-3M 0S"         
 "1d 5H 31M 0S"    "2d 8H 21M 0S"   
 "-32M 0S"         "2d 3H 10M 0S"

I have two issues

Whenever I tried to plot the visit duration I get a very weird graph and it doesn't arrange chronologically

Also, I wanted to plot the start and End visit time in one graph in lines to compare them, but with n luck

Any suggestion for a better way to compare the date and time? The data set is about 30 thousand something

Rio
  • 1
  • You can check the package `lubridate`, and you may want to check [this post](https://stackoverflow.com/questions/12649641/calculating-time-difference-in-r) and also [this one](https://stackoverflow.com/questions/39367359/calculate-time-difference-in-r) or [this one](https://stackoverflow.com/questions/25033585/calculating-time-difference-between-two-columns) – Mata Oct 07 '21 at 10:27
  • thanks for the comment @Mata all the posts are for the time difference of the same date, In my data, I need to know the difference in days, hours and mins, meaning some visits are last for more than one day so abstracting the time only will give me incorrect results – Rio Oct 07 '21 at 13:04

0 Answers0