如何在R中创建索引为两分钟的数据帧
我想创建一个给出一个日期的数据框(即01/01/2021 00:00:00),创建一个索引为两分钟的数据框,直到sysdate()。在这种情况下:如何在R中创建索引为两分钟的数据帧,r,dataframe,datetime,R,Dataframe,Datetime,我想创建一个给出一个日期的数据框(即01/01/2021 00:00:00),创建一个索引为两分钟的数据框,直到sysdate()。在这种情况下: 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 使用seq创建2分钟序列 create_time_series <- function(time) { data.frame(INDEX = seq(as.PO
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
使用
seq
创建2分钟序列
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
#...
#...
创建时间序列