Assuming below data
OriginId, OriginName, DestinationId, DestinationName,Time
1 , Origin 1, 1 , Destination 1 , 20
1 , Origin 1, 2 , Destination 2 , 25
2 , Origin 2, 3 , Destination 3 , 14
2 , Origin 2, 4 , Destination 4 , 29
This is a CSV which holds travel time between origins and destinations. I want to find the closest destination per origin. In other words, I have to group the data by OriginId and give rank to each group based on the time and get those rows which got rank 1. So the desired result for above data is:
OriginId, OriginName, DestinationId, DestinationName,Time(Minute)
1 , Origin 1, 1 , Destination 1 , 20
2 , Origin 2, 3 , Destination 3 , 14
Which R function do I need to use after group by?