I have a data frame (named as df) with single column of protein IDs and other file with two columns of protein IDs (named as df1). I need to find the df IDs present in either first or second column of df1 and extract corresponding Id from the df1.
df = data.frame(p = c("ENSG00000198400","ENSG00000066044","ENSG00000188612","ENSG00000177606","ENSG00000146648"))
df1 = data.frame(p1 = c("ENSG00000105647","ENSG00000110395","ENSG00000165119","ENSG00000160293","ENSG00000198400","ENSG00000198400"),p2 = c("ENSG00000198400","ENSG00000198400","ENSG00000198400","ENSG00000142949","ENSG00000112936","ENSG00000162434"))
Sample output:
df2= data.frame(p = c("ENSG00000198400","ENSG00000198400","ENSG00000198400","ENSG00000198400","ENSG00000198400"),p2 = c("ENSG00000105647","ENSG00000110395","ENSG00000165119","ENSG00000112936","ENSG00000162434"))