Calculate elapsed “times”, where the reference time depends on a factor
I'm trying to calculate elapsed times in a data frame, where the 'start' value for the elapsed time depends on the value of a factor column in the data frame. (To simply the question, I'll treat the time values as numeric rather than time objects - my question is about split-apply-combine, not time objects). My data frame looks like this: df <- data.frame(id=gl(2, 3, 5, labels=c("a", "b")), time=1:5) I'd like to calculate elapsed times by subtracting the minimum time in each factor level from each time (although for the sake of this example I'll just deal with numeric values, not time values).