Give it a try ave. Packages are not used.
transform(df, Diff = ave(as.numeric(Timestamp), Id, FUN = function(x) c(0, diff(x))/60))
giving:
Id Timestamp Event Diff
1 1 2015-11-06 06:11:43 mail subscribed 0
2 1 2015-11-06 06:15:43 Invoice created 4
3 1 2015-11-06 09:15:43 phone call 180
4 2 2015-11-07 08:15:43 New subscription 0
5 2 2015-11-07 08:20:43 Added to customer list 5
Note: . This was used to input data.frame,DF
Lines <- "Id, Timestamp, Event
1, 2015-11-06 06:11:43, mail subscribed
1, 2015-11-06 06:15:43, Invoice created
1, 2015-11-06 09:15:43, phone call
2, 2015-11-07 08:15:43, New subscription
2, 2015-11-07 08:20:43, Added to customer list"
df <- read.csv(text = Lines)
df$Timestamp <- as.POSIXct(df$Timestamp)
UPDATED in accordance with the comment.
source
share