I am running into a possible aggregate/summarise problem with this time series dataset.
Below is a dataset containing unique instances of a chat from a internet chatting system.
chatId agentId beginning_timestamp ending_timestamp answer
1 22 4/07/2016 9:00 4/07/2016 9:30 1
2 22 4/07/2016 9:26 4/07/2016 9:35 5
3 22 4/07/2016 9:15 4/07/2016 9:19 5
4 10 4/07/2016 11:17 4/07/2016 12:13 2
5 10 4/07/2016 11:29 4/07/2016 11:50 1
- The unique id field is chatId.
- agentId is a unique agent who received this chat
- beginning_timestamp is the time when the chat started
- ending_timestamp is the time when the chat ended
- answer is a continous variable used for later analysis
I would like to use dplyr (or anything else) to summarise the following dataset in this manner:
- For every group(agentId and chatId), find out if there is another chat that occurred within the same timeframe (from beginning_timestamp plus 5 minutes to ending_timestamp - 5 minutes)
- If there is a chat write out the fact that this unique chat occured while there was another chat ongoing.
Here is a resulting dataset with an additional column(multiple_chats = a discrete variable will do) that I would like to make:
chatId agentId beginning_timestamp ending_timestamp answer multiple_chats
1 22 4/07/2016 9:00 4/07/2016 9:30 1 1
2 22 4/07/2016 9:26 4/07/2016 9:35 5 0
3 22 4/07/2016 9:15 4/07/2016 9:19 5 1
4 10 4/07/2016 11:17 4/07/2016 12:13 2 1
5 10 4/07/2016 11:29 4/07/2016 11:50 1 1
Any answers are appreciated.