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
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
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
#...
#...