Currently, I have two data frames. The first df1 contains two columns which represent network ties. The other df2 contains a single column with the list of all cases for which I have attribute data.

I want to search for those cases from df2 in df1, if they are not present in one or both columns from df1, I want to delete that row. Thus, I will end up with a df1 that contains network ties between cases I have attribute data on. 

df1 has about 2.4 million ties (edgelist), and df2 has 34k individual cases.

This is what I have attempted after googling for a while:

First I duplicate the two columns on df1 to have a backup. 

```
library*dlypr)
df3<- df1%>%
     mutate(friendid = friendid %in% df2$V1,
            friendid = friendid*1.0) #converts boolean to numeric
df3<- df3%>%
     mutate(tieid= tieid%in% df2$V1,
            tieid= tieid*1.0)
#So what I think is going on here is that if the number is not found it turn the value into 0 and 1 if present. I do this for the two original columns from df1.

#Then I attempt to delete the rows by searching for 0 values on each column (2 and 3, which contain the edgelist).

df3<-df3[apply(df3[2],1,function(z) !any(z==0)),] 

df3<-df3[apply(df3[3],1,function(z) !any(z==0)),]

```

The process does delete a bunch of rows, but I end up with about 2k cases. That does not seem right. I attempted a similar approach doing Excel, but it has a limit on the number of rows you can load at once. After dividing the dataset into three different files and using Kutools, I ended up with about 74k cases. But since I was doing a lot of manual work, I am pretty sure there are errors in the excel work. R allows me to load up all the data at once, which would help in getting a more concrete result. 

Any help will be appreciated. Thank you

EDITED to provide more info:

```
> head(df1)
    ID     steamid    friendid daysknown    years         el1         el2
1    NA 7.65612e+16 7.65612e+16      2156 5.902806 7.65612e+16 7.65612e+16
2    NA 7.65612e+16 7.65612e+16      3480 9.527721 7.65612e+16 7.65612e+16
3    NA 7.65612e+16 7.65612e+16      1588 4.347707 7.65612e+16 7.65612e+16
4    NA 7.65612e+16 7.65612e+16       501 1.371663 7.65612e+16 7.65612e+16
5    NA 7.65612e+16 7.65612e+16       858 2.349076 7.65612e+16 7.65612e+16
6    NA 7.65612e+16 7.65612e+16       686 1.878166 7.65612e+16 7.65612e+16
> head(df2)
                 V1
1 76561197960265800
2 76561197960266000
3 76561197960266100
4 76561197960267800
5 76561197960268100
6 76561197960268400

```

Both columns steamid and friendid in df1 need to be ids available in df2$V1. If only one of the ids is present in the pair that row has to be removed, also if none are present too. The end df will have pairs of ids that can only be found in df2.