I have the following data:
df <- data.frame(A = c(1,2,3,4,5,6), B=c(\"P\",\"P\",\"P\",\"Q\",\"Q\",\"Q\"), C=c(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\")) df ##
You can try
library(dplyr) df %>% group_by(B) %>% filter(A==min(A)) # A B C #1 1 P a #2 4 Q d
Or
library(data.table) setDT(df)[, .SD[A==min(A)], B]
Or using base R
base R
df[with(df, ave(A, B, FUN=min)==A),] # A B C #1 1 P a #4 4 Q d