保留具有特定日志的用户的所有日志(r语言)

时间:2016-09-19 12:32:38

标签: r

我有这样的表(输入):

User   Event

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

我需要保留事件(输出)中没有rate的用户的所有日志:

User   Event

Mike   error
Mike   buy
Mike   rate
Mike   like

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

dplyr解决方案可以是:

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