I have the following two data frames of user events:

data.favorite (*user* favorited *item* at *time*)

```
           user   item   time   event
1             1      A      2     fav
2             1      B      6     fav
3             2      D      9     fav
4             3      A      5     fav

```

data.view (*user* viewed *item* at *time*)

```
           user   item   time   event
1             1      A      1    view
2             1      A      3    view
3             1      B      4    view
4             1      B      5    view
5             1      B      7    view
6             1      C      8    view
7             3      A      2    view
8             3      A      9    view

```

I now only want to keep those events of data.view that occured after that user favorited that item. E.g. row 1 of data.view would be removed, as user 1 favorited item A at 2. The view event at time 3 however would remain, as the user had already favorited the item at that point. So, the result for this example should look like this:

```
           user   item   time   event
1             1      A      3    view
2             1      B      7    view
3             3      A      9    view

```

My current approach is way too slow. I apply a custom function to data.view:

```
wasFav = function(u, i, t) {
  favs = data.favorite %>% filter(user == u, item == i, time < t)
  return(nrow(favs) > 0)
}

```

Any ideas for a faster approach?