Smasell Smasell - 2 months ago 7
R Question

Leave all logs from users who have specific log (r language)

I have my table like this(input):

User Event

Mike error
Mike buy
Bony error
Bony like
Mike rate
Mike like


I need to leave all logs from users who do not have
rate
in Event(output):

User Event

Mike error
Mike buy
Mike rate
Mike like


Thanks for help!

Answer

A dplyr solution can be :

library(dplyr)
df %>%
   group_by(User) %>%
   filter(sum(Event == 'rate') > 0)

#   User  Event
#  <fctr> <fctr>
#1   Mike  error
#2   Mike   buy
#3   Mike   rate
#4   Mike   like