在r中的日期时间变量中汇总时间
我一直在寻找解决问题的解决方案,我认为很容易解决,但似乎并非如此。我正在尝试将DateTime变量汇总到接下来的5分钟。
Incidents<- structure(list(Event.Id = c(240252L, 240258L, 240261L, 240264L,
240294L, 240313L, 240314L, 240315L, 240331L, 240343L, 240350L,
240358L, 240379L, 240381L, 240396L), DateTime = structure(c(1427868300,
1427872800, 1427873100, 1427873700, 1427881500, 1427890260, 1427890860,
1427890980, 1427900160, 1427902860, 1427904480, 1427906700, 1427910900,
1427911920, 1427919360), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(5L,
11L, 14L, 15L, 40L, 59L, 60L, 61L, 77L, 90L, 96L, 103L, 122L,
123L, 135L), class = "data.frame")
我用过:
Incidents$DateTime2<- round_date(Incidents$DateTime,unit="5 minutes")
但是,这是最接近5分钟的时间。我想要接下来的5分钟。 我在下面尝试了此代码:
Incidents<- Incidents %>% mutate(time = as.numeric(substr(DateTime, 16,16)))
Incidents$time <- ifelse(Incidents$time <6,5- Incidents$time, 10 - Incidents$time)
minut<- minutes(5)
Incidents$DateTime3<- ifelse(Incidents$time <3, Incidents$DateTime2 + minut, Incidents$DateTime2)
但是,这给了我无法将其转换为日期时间变量的数字值。
I have been looking for a solution for a problem I thought is easy to solve but it doesn't seem so. I am trying roundup a DateTime Variable to the next 5 minutes.
Incidents<- structure(list(Event.Id = c(240252L, 240258L, 240261L, 240264L,
240294L, 240313L, 240314L, 240315L, 240331L, 240343L, 240350L,
240358L, 240379L, 240381L, 240396L), DateTime = structure(c(1427868300,
1427872800, 1427873100, 1427873700, 1427881500, 1427890260, 1427890860,
1427890980, 1427900160, 1427902860, 1427904480, 1427906700, 1427910900,
1427911920, 1427919360), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(5L,
11L, 14L, 15L, 40L, 59L, 60L, 61L, 77L, 90L, 96L, 103L, 122L,
123L, 135L), class = "data.frame")
I used:
Incidents$DateTime2<- round_date(Incidents$DateTime,unit="5 minutes")
However, this rounds the time to the closest 5 minutes. I want the next 5 minutes instead.
I tried this code below:
Incidents<- Incidents %>% mutate(time = as.numeric(substr(DateTime, 16,16)))
Incidents$time <- ifelse(Incidents$time <6,5- Incidents$time, 10 - Incidents$time)
minut<- minutes(5)
Incidents$DateTime3<- ifelse(Incidents$time <3, Incidents$DateTime2 + minut, Incidents$DateTime2)
However, this gives me numeric values that I could not convert to date time variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论