Find index of first specific result in each group from r -


i have dataset below: outcome have no relationship contact_date, when subscriber response cold call, mark successful contact attempt(1) else (0). count how many times called subscriber.

 subscriber_id   outcome contact_date  queue multiple_number count            (int)   (int)       (date) (fctr)           (int) (int) 1              1       1   2015-01-29      2               1     1 2              1       0   2015-02-21      2               1     2 3              1       0   2015-03-29      2               1     3 4              1       1   2015-04-30      2               1     4 5              2       0   2015-01-29      2               1     1 6              2       0   2015-02-21      2               1     2 7              2       0   2015-03-29      2               1     3 8              2       0   2015-04-30      2               1     4 9              2       1   2015-05-31      2               1     5 10             2       1   2015-08-25      5               1     6 11             2       0   2015-10-30      5               1     7 12             2       0   2015-12-14      5               1     8 13             3       1   2015-01-29      2               1     1 

i count number first outcome ==1 each subscriber, please tell me how can it? final data set is: (please noticed may don't have success call, in case, mark first_success 0)

subscriber_id first_success 1                1 2                5 3                1 ... 

require(dplyr)      data %>% group_by(subscriber_id) %>% filter(outcome==1) %>% slice(which.min(contact_date)) %>% data.frame() %>%  select(subscriber_id,count) 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -