User Tools

Site Tools


group_and_filter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

group_and_filter [2015/12/16 13:25] (current)
vincenzo created
Line 1: Line 1:
 +<code c>
 +# 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
 +</​code>​
group_and_filter.txt ยท Last modified: 2015/12/16 13:25 by vincenzo