-1

Any good idea to fast filter the following dataframe (the original is big): for rows with same value of 'member', only keep the one with smallest corresponding 'height':

group   member  height
A   m   1
B   m   2
C   g   3

The result will be:

group   member  height
A   m   1
C   g   3
yliueagle
  • 1,191
  • 1
  • 7
  • 22

1 Answers1

0

You could split the data.frame and then return just the lines which corresponds to the minimum:

d <- data.frame(group = factor(LETTERS[1:3]), member = factor(rep(c("m", "g"), 2:1)), 
                height = 1:3)

do.call(rbind, lapply(split(d, d$member), function(.) .[which.min(.$height),]))
#   group member height
# g     C      g      3
# m     A      m      1

I leave it to you to remove unwanted rownames and to put it in the order you want it.

thothal
  • 16,690
  • 3
  • 36
  • 71