Gene-filterin In R
I am trying to filter out genes from my gene-fusion excel file. I want to remove any gene which is getting repeated more than 10 times in the column. I am doing this in R.
Thanks in advance.
• 28 views
Assuming you have your data stored in a
df, you could use
dplyr::n to count the number of instances of each value in the target column (e.g.,
a), and add these as a new column (
b). Then you can filter the
data.frame using this new column.
library(magrittr) library(dplyr) df %>% group_by(a) %>% mutate(b = n()) %>% ungroup() %>% filter(b <= 10) %>% select(-b) `