EcoFlux
EcoFlux

Reputation: 35

Rounding data collected at changing 30 min intervals into set 30 min intervals

I have a dataset in which measurements have been collected at 30 min intervals over a four year period. However, since this data was collected over such a long period, there have been several starts and stops on the recording instrument. Data is still being recorded at 30 min intervals, but the interval is not consistent across the collection period.

For example say I have 100 days of data where the interval is: "2015-08-01 09:03:00, 2015-08-01 09:33:00, 2015-08-01 10:03:00" etc...

Then then after a short gap the next 50 days are something like this: "2016-02-01 09:13:00, 2016-02-01 09:43:00, 2016-02-01 10:13:00" etc...

I would like to apply something that would "round" the data into set 30 min intervals that are consistent across all four years, like: "2015-08-01 09:00:00, 2015-08-01 09:30:00, 2015-08-01 10:00:00" etc.

Thank you.

Upvotes: 0

Views: 101

Answers (1)

iod
iod

Reputation: 7592

lubridate has floor_date which can do what you're looking for:

dates<-c("2016-02-01 09:13:00","2016-02-01 09:33:00")
floor_date(as_datetime(dates), unit="30 minutes")

[1] "2016-02-01 09:00:00 UTC" "2016-02-01 09:30:00 UTC"

Of course, if one interval is, say, 9:29 and the next one is 10:02, you'll have a missing value at 9:30. Not sure how that can possible be avoided given the nature of your data.

Upvotes: 1

Related Questions