0

I want to create a Dataframe giving one date (i.e. 01/01/2021 00:00:00) create a Dataframe with index by two minutes until sysdate(). in this case:

INDEX
01/01/2021 00:00:00
01/01/2021 00:02:00
01/01/2021 00:04:00
...
04/03/2021 11:56:00
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Alberto Aguilera
  • 311
  • 1
  • 5
  • 13

1 Answers1

0

Use seq to create 2-minute sequence.

create_time_series <- function(time) {
  data.frame(INDEX = seq(as.POSIXct(time), Sys.time(), by = '2 mins'))
}

create_time_series('2021-01-01')

#                INDEX
#1 2021-01-01 00:00:00
#2 2021-01-01 00:02:00
#3 2021-01-01 00:04:00
#4 2021-01-01 00:06:00
#5 2021-01-01 00:08:00
#6 2021-01-01 00:10:00
#...
#...

create_time_series('2021-01-10 02:00:00')

#                INDEX
#1 2021-01-10 02:00:00
#2 2021-01-10 02:02:00
#3 2021-01-10 02:04:00
#4 2021-01-10 02:06:00
#5 2021-01-10 02:08:00
#6 2021-01-10 02:10:00
#...
#...
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213