Reputation: 1595
I've the following dataframe (With many records) and would like to retrieve the entire row for each day with maximum differences.
require(dplyr)
# This gets the maximum value for each date
maxInfo = results %>% group_by(t) %>% summarise(Value = max(differences))
I'm able to get the max value for each day but how to get the entire row?
Upvotes: 1
Views: 45
Reputation: 25323
A possible solution, using slice_max
:
library(dplyr)
results %>% group_by(t) %>% slice_max(differences)
Upvotes: 3
Reputation: 1873
data.table
method if speed is important
results[ results[, .I[ differences == max(differences )], .(t)]$V1 ]
Upvotes: 1