I have about a million data points of two columns: time and quantity. times are in 24 hours format (11:23:08 AM), and many of them are repeated many times (about 10-100 duplicates for each seconds). I am coding in R and I want a third column to sum (add) all the quantities for the last 5 seconds of time. the values for each specific seconds would become duplicates obviously.
It seems to be very easy but traditionally I just know writing two "for loops" in other programs to search for the condition of time in the last 5 seconds. However this would be very time-consuming in R . I need a second technique.