Returning first row of group

By reproducing the example data frame and testing it I found a way of getting the needed result:

  1. Order data by relevant columns (ID, Start)

    ordered_data <- data[order(data$ID, data$Start),]

  2. Find the first row for each new ID

    final <- ordered_data[!duplicated(ordered_data$ID),]

Leave a Comment