how to find occurences between a character list and a dataset in R?

Viewed 35

I have a list of genes:

genelist = chr [1:30] "CIK2"  "RED4"  "DFG"  "GGG" "VCA" "CFD" ....

And i have 30 genesets of this class :

[1] "tbl_df"     "tbl"        "data.frame"

In which i've two columns:

   set.           gene.  

1 mammal tissue  CIK2

2 mammal tissue RED4

3 mammal tissue DFG

4 mammal tissue GGG

5 liver tissue CIK2

6 liver tissue RED4 

7 liver tissue ALN

6 brain tissue CIK2

...

As output I would like occurrences of my list in gene sets, for example:

CIK2 in 3 genesets (genesets_names1, genesets_names2, geneset_names3).
RED4 in 2 genesets 
...
...

I tried with some code like this but nothing:

for (gene in genelist) {
  for (set in unique(gene_sets$set)){
    occurrence = gene %in% set
  }
}
0 Answers
Related