I\'ve created a dataframe with data :
idCol <- c(\'1\',\'1\',\'2\',\'2\')
stepCol <- c(\'step1\' , \'step2\' , \'step1\' , \'step2\')
timestampCol <- c
I did some minor editing to your code but basically you need to associate the results of ymd_hms
with your mydata
:
mydata$diffTime <- c(0, difftime(lubridate::ymd_hms(mydata$timestamp[-1]),
lubridate::ymd_hms(mydata$timestamp[-nrow(mydata)]), units="hours"))
diffTime <- mydata %>% group_by(id) %>% summarize(mean(diffTime))
Returns:
R> diffTime
# A tibble: 2 x 2
id `mean(diffTime)`
1 1 0.008333
2 2 0.033333