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
Here is a ddply solution
ddply(df, .(id), summarize, time = time, elapsed = seq(length(id))-1)
and one using rle instead
df$elapsed <- unlist(sapply(rle(as.numeric(df$id))$lengths, seq))-1