指示日期属于哪个间隔 [英] indicateing to which interval a date belongs

查看:75
本文介绍了指示日期属于哪个间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

4/1/2014 0:11   40.769  -73.9549    B02512|
4/1/2014 0:17   40.7267 -74.0345    B02512|
4/1/2014 0:21   40.7316 -73.9873    B02512|
4/1/2014 0:28   40.7588 -73.9776    B02512|
4/1/2014 0:33   40.7594 -73.9722    B02512|
4/1/2014 0:33   40.7383 -74.0403    B02512|

我创建了一个类似这样的时间间隔对象 C--2014-04-11 00:15:00 UTC 2014-04-11 00:15:00 UTC(部分) 我想做的是在原始数据中添加一列,该列指示每一行的 哪个时间间隔(由开始时的单个时间点表示 时间间隔)它属于

and i created a time interval objet that lokks like this C--2014-04-11 00:15:00 UTC 2014-04-11 00:15:00 UTC(part of it ) what i want to do is to to add a column to the raw data, that indicates for each row, for which time interval (which is represented by a single timepoint at the beginning of the time interval) it belongs

所以我的数据看起来像这样:

so my data would look like this :

4/1/2014 0:11   40.769  -73.9549    B02512  4/1/2014 0:00|
4/1/2014 0:17   40.7267 -74.0345    B02512  4/1/2014 0:15|

我该怎么做?

推荐答案

使用lubridatefloor_date函数:

df$interv<-lubridate::floor_date(df$time, unit="15 minutes")

(这假设您的时间列是某种公认的日期时间格式(例如POSIXt),似乎与您的样本格式无关.)

(This assumes that your time column is some recognized date-time format (e.g., POSIXt), which it doesn't seem to be from your sample's formatting.)

例如:

a<-Sys.time()
a
[1] "2019-01-08 09:22:22 EST"
floor_date(a,unit="15 minutes")
[1] "2019-01-08 09:15:00 EST"

这篇关于指示日期属于哪个间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆