问题
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|
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|
how can i do that ?
回答1:
Using lubridate
's floor_date
function:
df$interv<-lubridate::floor_date(df$time, unit="15 minutes")
(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.)
For example:
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"
来源:https://stackoverflow.com/questions/54093675/indicateing-to-which-interval-a-date-belongs