# Example data
data <- data.frame(
start = c(0, 0, 1, 1, 2, 2),
end = c(1, 1, 2, 2, 3, 3),
scientific_name = c(
"Species A",
"Species B",
"Species A",
"Species B",
"Species A",
"Species B"
),
common_name = c(
"Common A",
"Common B",
"Common A",
"Common B",
"Common A",
"Common B"
),
confidence = c(0.1, 0.2, 0.5, 0.3, 0.7, 0.8)
)
data
# Get top prediction for each time interval
get_top_prediction(data)
# Get top prediction for a specific time interval
get_top_prediction(data, filter = list(start = 1, end = 2))
# The same thing can be done using dplyr
if (FALSE) {
data |>
dplyr::group_by(start, end) |>
dplyr::slice_max(order_by = confidence)
}
Run the code above in your browser using DataLab