how to select columns based on condition using dplyr?

dear all
Good evening
i have data like this
column selection
now i would like select rows matching to my condition in any of ID1 and ID2 or both of ID1 and ID2 cond <- c("A/T","A/G","A/C","T/A","T/G","T/C","G/A","G/T","G/C","C/A","C/T","C/G","MISSING) and also want to select column containing same letter for example SNP1 having A/A in ID1 and ID2. Now i would like to get selected all the SNPs from my data except SNP2 as my result. i used the following code using dplyr package but not getting expected results. here is my code

cond <- c("A/T", "A/G", "A/C", "T/A", "T/G", "T/C", "G/A", "G/T", "G/C", "C/A", "C/T", "C/G","MISSING")
test %>% select(starts_with("SNP") & where(~ any(.x %in% cond))) ### select columns whos name starts with SNP
test1 %>% select(where(~ any(.x %in% cond)))

can anyone help me to sort out my problem, any help in this regard will be highly appreciated
Thanks in advance

If I'm not mistaken, select selects the columns, however your data are in rows. So instead of select I would give a try with filter.

1 Like

This topic was automatically closed 21 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.