I've been trying to use answers to other similar questions but had no luck. I have 2 datasets:
#df1:
Gene
ACE
BRCA
HER2
#df2:
Gene interactors
GP5 ACE, NOS, C456
TP53 NOS, BRCA, NOTCH4
I am looking to add a column to my first dataset to identify genes which appear as interactors in my second dataset.
Output:
#df1:
Gene Matches
ACE TRUE
BRCA TRUE
HER2 FALSE
Currently I'm trying df1$Matches <- mapply(grepl, df1$Gene, df2$interactors)
This runs but when I increase the number of genes in df1 the number of matches drops, which doesn't make sense as I don't remove any genes that were ran originally, making me think this isn't working like I expect.
I've also tried:
library(stringr)
df1 %>%
+ rowwise() %>%
+ mutate(exists_in_title = str_detect(Gene, df2$interactors))
Error: Column `exists_in_title` must be length 1 (the group size), not 3654
In addition: There were 50 or more warnings (use warnings() to see the first 50)
I've also tried a dplyr version of this with the same error.
What other ways I can approach this? Any help would be appreciated.
Input data:
dput(df1)
structure(list(Gene = c("ACE", "BRCA", "HER2")), row.names = c(NA,
-3L), class = c("data.table", "data.frame"))
dput(df2)
structure(list(Gene = c("GP5", "TP53"), interactors = c("ACE, NOS, C456",
"NOS, BRCA, NOTCH4")), row.names = c(NA, -2L), class = c("data.table",
"data.frame"))