I have a dataframe in R containing the columns ID.A, ID.B and DISTANCE, where distance represents the distance between ID.A and ID.B. For each value (1->n) of ID.A, there ma
You can also do it easily in base R. If dat is your dataframe,
dat
do.call(rbind, by(dat, INDICES=list(dat$ID.A), FUN=function(x) head(x[order(x$DISTANCE), ], 1)))