1

I would like to filter my data frame to remove duplicated IDs in "Gene" and keep only the one with lowest "Pval". Please see my example:

in

Gene Pval
buc  0.01
buc  0.3
abad 0.0002
abad 0.01
myc  0.1
p53  0.03

out

Gene Pval
buc  0.01
abad 0.0002
myc  0.1
p53  0.03
user2300940
  • 2,355
  • 1
  • 22
  • 35

1 Answers1

1

We can use:

library(dplyr)

df %>% 
  group_by(Gene) %>% 
  filter(Pval==min(Pval)) %>% 
  unique()
NelsonGon
  • 13,015
  • 7
  • 27
  • 57