I have a data frame that stores call records from a call center. My purpose is to count how many records exist per time interval, for example, in a time interval of 30 minutes there may be three call records (that is, three calls entered within that specific time interval); In case there are no records for that time interval, then my counter should show me a zero value.
This post was useful but I do not achieve that when there are no records in a time interval it shows me a zero value.
This is the structure of my call_log
:
Classes ‘data.table’ and 'data.frame': 24416 obs. of 23 variables:
$ closecallid : int 1145000 1144998 1144997 1144996 1144995 1144991 1144989 1144987 1144986 1144984 ...
$ lead_id : int 1167647 1167645 1167644 1167643 1167642 1167638 1167636 1167634 1167633 1167631 ...
$ list_id :integer64 998 998 998 998 998 998 998 998 ...
$ campaign_id : chr "212120" "212120" "212120" "212120" ...
$ call_date : POSIXct, format: "2019-08-26 20:25:30" "2019-08-26 19:32:28" "2019-08-26 19:27:03" ...
$ start_epoch : POSIXct, format: "2019-08-26 20:25:30" "2019-08-26 19:32:28" "2019-08-26 19:27:03" ...
$ end_epoch : POSIXct, format: "2019-08-26 20:36:25" "2019-08-26 19:44:52" "2019-08-26 19:40:23" ...
$ length_in_sec : int 655 744 800 1109 771 511 640 153 757 227 ...
$ status : chr "Ar" "Ar" "Ar" "Ar" ...
$ phone_code : chr "1" "1" "1" "1" ...
$ phone_number : chr "17035555" "43667342" "3135324788" "3214255222" ...
$ user : chr "jfino" "jfino" "jfino" "jfino" ...
$ comments : chr "AUTO" "AUTO" "AUTO" "AUTO" ...
$ processed : chr "N" "N" "N" "N" ...
$ queue_seconds : num 0 524 692 577 238 95 104 0 0 0 ...
$ user_group : chr "CEAS" "CEAS" "CEAS" "CEAS" ...
$ xfercallid : int 0 0 0 0 0 0 0 0 0 0 ...
$ term_reason : chr "CALLER" "CALLER" "CALLER" "AGENT" ...
$ uniqueid : chr "1566869112.557969" "1566865941.557957" "1566865611.557952" "1566865127.557947" ...
$ agent_only : chr "" "" "" "" ...
$ queue_position: int 1 2 2 2 1 2 1 1 1 1 ...
$ called_count : int 1 1 1 1 1 1 1 1 1 1 ...
And, this is my code
df <- setDT(call_log)[ , list(number_customers_arrive = sum(called_count)), by = cut(call_date, "30 min")]
Thanks in advance.