vendredi 29 janvier 2021

How do I use grepl to filter out based off matches from a string of characters?

I have a list of gene names that I am trying to filter out of a larger data set using grepl. For example:

gene_list <- c(geneA, geneB, geneC)
data <- c(XXXgene1, XXXgene2, XXXgeneF, XXXgeneA, XXXgeneB)
select_grepl <- data %>% filter(grepl(c(gene_list), data)==T)

I have tried the grepl code above but since the pattern is > 1 they only use the first geneA to search within the string. If I change c(gene_list) to a single pattern like "geneA", then the code works. Is there another solution?

Aucun commentaire:

Enregistrer un commentaire