Search for text in multiple columns

Hello,

I have a table where I want to search "GO:0003700" in more than one column (columns: GO1 to GO11). I want to have a table with all the lines where "GO:0003700" appears. So far my Markdown looks as follows, I can only search in one column at a time:

DEGs <- read_excel("DEG_allGenes.xlsx")

colnames(DEGs)

dim(DEGs)

DEGs_GO <- DEGs[DEGs$GO1 %in% c("GO:0003700"),]

This is probably total easy, but since I am at the very beginning with R studio I would really appreaciate some help.

1 Like

Hi @LaraCanovai
Try with this code.

library(dplyr)
DEGs %>%
 filter(if_any(everything(), ~str_detect(tolower(.), "GO:0003700")))

Thank you, this works for me! I just had to deleat the GO: because of the headers, but that is totally fine. Thank you a lot!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.