Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

calculating the duration of a ticket in R

$
0
0

I have a set of customers, their daily activity log, and if they had and issue raised on their account. A customer can have an issue raised on their account multiple times throughout their duration as a customer and an issue can stay raised for multiple days. I want to figure out the duration that an issue was raised on each account. The dates can start from anywhere and the issue can occur at anytime, saving as TRUE=1 and FALSE=0 in the sample below.

Some sample data:

df <- data.frame(customer= c('AB','AB','AB', 'AB','AB','BC','BC','BC','CD','CD','CD','CD'), date=as.Date(c("11/09/2000","12/09/2000","13/09/2000","14/09/2000","15/09/2000","13/09/2000","14/09/2000","15/09/2000","23/05/2001","24/05/2001","25/05/2001", "26/05/2001"), "%d/%m/%Y"), issue=c(0,1,1,1,1,0,0,1,1,0,1,1))

I tried making an index counter, along with some other variations found in this thread: Calculate days since last event in R, but then it doesn't count the continuous days (i.e. AB kept showing up with duration of 1 on each day instead of 2,3,4), as shown below:

customerdateissueduration
AB2000-09-1100
AB2000-09-1211
AB2000-09-1311
AB2000-09-1411
AB2000-09-1511

What I need the output to be something similar to:

customerdateissueduration
AB2000-09-1100
AB2000-09-1211
AB2000-09-1312
AB2000-09-1413
AB2000-09-1514
BC2000-09-1300
BC2000-09-1400
BC2000-09-1511
CD2000-05-2311
CD2000-05-2400
CD2000-05-2511
CD2000-05-2612

Any help would be great. Thanks!


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>