User Tools

Site Tools


group_and_filter
# use the pipe operator for pipe the grouping 
# and filter that the first event should be 'install' and the second 'sale'
 
df1 %>%
  group_by(id) %>%
    filter(first(event)=='install' & event[2L]=='sale')
 
 
 
df1 %>% 
     group_by(id) %>%
     mutate(ind= first(event)=='install' & lead(event, default='sale')=='sale') %>%
     filter(all(ind)) %>% 
     ungroup() %>% 
     select(-ind)
 
 
# http://stackoverflow.com/questions/33501328/dealing-with-grouped-dataset-in-r
group_and_filter.txt · Last modified: 2015/12/16 13:25 by vincenzo