答案 0 :(得分:0)
试试这个:
# generate data
set.seed(1000)
df <- data.frame(Time = sort(sample(seq(c(ISOdate(2017,3,20)), by = "min", length.out = 150), 9)),
User = rep(LETTERS[1:3], each = 3),
Action = rep(1:3, times = 3),
stringsAsFactors = FALSE)
# get time between first and last action
library(dplyr)
df %>%
group_by(User) %>%
summarise(time_spent = max(Time) - min(Time))