【发布时间】:2021-09-15 19:55:28
【问题描述】:
我有一个看起来像这样的表(1 个示例 - 总共 200 万行):
tweet_id | id | group | created_at | tweet | response_tweet_id
1 sprintcare Support Tue Oct 31 22:10:47 +0000 2017 @115712 I understand. I would like to assist you. 2
2 115712 Customer Tue Oct 31 22:11:45 +0000 2017 @sprintcare and how do you propose we do that? NA
3 115712 Customer Tue Oct 31 22:08:27 +0000 2017 @sprintcare I have sent several private messages. 1
4 sprintcare Support Tue Oct 31 21:54:49 +0000 2017 @115712 Please send us a Private Message. 3
5 115712 Customer Tue Oct 31 21:49:35 +0000 2017 @sprintcare I did. 4
6 sprintcare Support Tue Oct 31 21:46:24 +0000 2017 @115712 Can you please send us a private message. 5,7
8 115712 Customer Tue Oct 31 21:45:10 +0000 2017 @sprintcare is the worst customer service 9,6,10
11 apple Support Tue Oct 31 22:10:35 +0000 2017 @115713 This is saddening to hear. NA
12 115713 Customer Tue Oct 31 22:04:47 +0000 2017 @apple My phone is not working. Help! 11
引用第一行时,我们可以看到响应 tweet_id 1(标记为 2)时第一个支持 tweet 响应的时间。
理想情况下 - 我想计算每条响应推文需要多长时间 - 从支持到客户订购。
我想计算两个值:
-
向支持人员发出第一条推文之间的响应时间(tweet_id、response_tweet_id 和 created_at)。对于第一行 - 时差是: 2017 年 10 月 31 日星期二 22:10:47 +0000 - 2017 年 10 月 31 日星期二 22:08:27 +0000 = 00:02:20。
-
从第一条推文从支持到给每个客户的最后一条推文之间的总响应时间。在下面的示例中 - 它本质上是相对于支持时间发出的第一条推文,以及在下一个唯一 ID 发挥作用之前发出的最后一条推文。
根据每个组(100 多家独特的公司),所需的输出如下所示:
id | group | Avg_response_time_per_tweet (in minutes) | Total_avg_response_time (in minutes)
sprintcare Support #### ####
apple Support #### ####
【问题讨论】:
-
当你说平均响应时间时,你想怎么计算。是否基于 sprintcare 的 created_at 相对于 115712 值的差异,然后取每次 sprintcare 出现的平均值
-
好的,平均响应时间是多少?是从第一条推文到第二条的时间吗?还是群组中最后一条推文的第一条推文?
-
预期的并不完全清楚。也许
df1 %>% mutate(created_at = as.POSIXct(created_at, format = '%a %b %d %H:%M:%S +0000 %Y')) %>% group_by(group2 = cumsum(group == "Support")) %>% summarise(id = first(id), group = first(group), avg = mean(difftime(first(created_at), created_at[-1], units = "sec"))) -
抱歉 - 我根据您的两个问题更新了所需的输出。