繁体   English   中英

如何根据 R 中的持续时间(显示开始和结束时间,以及持续时间以小时和分钟为单位)计算最长日期

[英]how to calculate the longest date based on time duration (display begin and end time, and duration in hours and minutes) in R

以下是我拥有的数据:

date
2020-04-06 07:36:05
2020-04-08 03:26:33
2020-04-08 03:30:29
2020-04-09 01:21:49
2020-04-12 03:11:57
2020-04-13 01:56:58
2020-04-18 07:17:08
2020-04-18 07:33:15
2020-04-24 01:17:23
2020-04-24 01:17:27
2020-04-24 01:17:42
2020-04-29 02:25:18
2020-04-30 02:08:01
2020-05-06 02:36:26
2020-05-06 02:36:46
2020-05-06 02:46:24
2020-05-06 02:52:39
2020-05-06 02:52:40
2020-05-06 02:52:56
2020-05-06 02:53:13
2020-05-06 03:03:22
2020-05-06 04:24:42
2020-05-13 02:42:07
2020-05-13 04:13:59
2020-05-13 04:14:23
2020-05-17 04:04:15
2020-05-17 04:04:26
2020-05-17 04:05:17
2020-05-19 08:57:26
2020-05-23 10:19:36
2020-05-23 10:21:07
2020-05-23 10:22:00
2020-06-01 12:14:34
2020-06-18 12:47:55
2020-06-24 06:11:17
2020-06-24 06:11:42
2020-06-24 06:13:30
2020-06-24 07:24:20
2020-06-28 04:01:00
2020-06-28 04:01:23
2020-06-28 04:02:47
2020-06-28 04:13:29
2020-06-28 04:17:47

我想按 R 中的日期计算以小时和分钟为单位的时间的最长持续时间,并以小时和分钟显示开始、结束时间和持续时间

以下是我想要实现的 output:

Date        begin_time    end_time   duration
2020-05-06   02:36        04:24       1:48

帮助表示赞赏!

我会像这样使用tidyverselubridate ...

library(tidyverse)
library(lubridate)
df %>%
  group_by(Date = as_date(floor_date(date, "day"))) %>%
  summarize(begin_time = format(min(date), "%H:%M"), 
            end_time = format(max(date), "%H:%M"), 
            duration = format(floor_date(as_datetime("2020-01-01") + (max(date) - min(date)), "minute"), "%H:%M"))

...以这个框架结束:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM