4

I'm having trouble creating a time series (POSIXct or dttm column) with a row every 15 minutes.

Something that will look like this for every 15 minutes between Jan 1st 2015 and Dec 31st 2016 (here as month/day/year hour:minutes):

1/15/2015 0:00
1/15/2015 0:15
1/15/2015 0:30
1/15/2015 0:45
1/15/2015 1:00

A loop starting date of 01/01/2015 0:00 and then adding 15 minutes until 12/31/2016 23:45?

Does anyone has an idea of how this can be done easily?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Guillermo.D
  • 399
  • 2
  • 14

2 Answers2

15

Little bit easier to read

library(lubridate)
seq(ymd_hm('2015-01-01 00:00'),ymd_hm('2016-12-31 23:45'), by = '15 mins')
B Williams
  • 1,992
  • 12
  • 19
1
intervals.15.min <- 0 : (366 * 24 * 60 * 60 / 15 / 60)
res <- as.POSIXct("2015-01-01","GMT") + intervals.15.min * 15 * 60
res <- res[res < as.POSIXct("2016-01-01 00:00:00 GMT")]
head(res)
# "2015-01-01 00:00:00 GMT" "2015-01-01 00:15:00 GMT" "2015-01-01 00:30:00 GMT"
tail(res)
# "2015-12-31 23:15:00 GMT" "2015-12-31 23:30:00 GMT" "2015-12-31 23:45:00 GMT"
Bulat
  • 6,869
  • 1
  • 29
  • 52
  • I wasn't able to get how it worked but it worked. It will be awesome if you explain a little bit. – Guillermo.D Mar 31 '17 at 22:33
  • 1
    first i create a vector of 15 intervals in seconds for the whole year, after that i just add this vector to the starting date to get a vector of timestamps – Bulat Apr 01 '17 at 07:27