How do I aggregate 1 minute data into 15 minutes

夙愿已清 提交于 2021-01-28 22:52:41

问题


I have 1 minute data, I was wondering how do I aggregate (split) it into 15 minute data in R. I am using Rstudio user interface.

head(FW20_1min)
                    Open High  Low Close Volume
2010-04-19 08:31:00 2536 2537 2531  2532   2459
2010-04-19 08:32:00 2532 2535 2531  2533    625
2010-04-19 08:33:00 2532 2534 2531  2534    405
2010-04-19 08:34:00 2534 2535 2534  2534    179
2010-04-19 08:35:00 2534 2536 2534  2535    217
2010-04-19 08:36:00 2535 2536 2534  2534    162

The structure of the data is :

str(FW20_1min)
An ‘xts’ object on 2010-04-19 08:31:00/2010-04-19 16:30:00 containing:
  Data: num [1:465, 1:5] 2536 2532 2532 2534 2534 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:5] "Open" "High" "Low" "Close" ...
  Indexed by objects of class: [POSIXlt,POSIXt] TZ: 
  xts Attributes:  
 NULL

The dput() is:

dput(head(FW20_1min))
structure(c(2536, 2532, 2532, 2534, 2534, 2535, 2537, 2535, 2534, 
2535, 2536, 2536, 2531, 2531, 2531, 2534, 2534, 2534, 2532, 2533, 
2534, 2534, 2535, 2534, 2459, 625, 405, 179, 217, 162), class = c("xts", 
"zoo"), .indexCLASS = c("POSIXlt", "POSIXt"), tclass = c("POSIXlt", 
"POSIXt"), .indexTZ = "", tzone = "", index = structure(c(1271658660, 
1271658720, 1271658780, 1271658840, 1271658900, 1271658960), tzone = "", tclass = c("POSIXlt", 
"POSIXt")), .Dim = c(6L, 5L), .Dimnames = list(NULL, c("Open", 
"High", "Low", "Close", "Volume"))

回答1:


split(FW20_1min, "minutes", k=15)

or

to.period(FW20_1min, "minutes", 15) # or to.minutes15(FW20_1min)

depending on what you want to do



来源:https://stackoverflow.com/questions/23616438/how-do-i-aggregate-1-minute-data-into-15-minutes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!