[Solved] first occurrence of age in a nuggets eating contest


We can use data.table to get the fastest extraction using either unique with by option

unique(df2, by = "Person")

Or extracting with row index

setDT(df2)[df2[, .I[1L],Person]$V1]

Update

If we need the minimum ‘Age’ row per ‘Person

setDT(df2)[, .SD[which.min(Age)], Person]

Or if we prefer dplyr, then

library(dplyr)
df2 %>% 
   group_by(Person) %>%
   slice(1L)

Update

df2 %>%
    group_by(Person) %>%
    filter(Age == min(Age))

Or without using any external library

df2[with(df2, Age==ave(Age, Person, FUN = min)),]

6

solved first occurrence of age in a nuggets eating contest