如何将1分钟数据汇总到15分钟

时间:2014-05-12 18:41:19

标签: r split

我有1分钟的数据,我想知道如何将其聚合(拆分)为R中的15分钟数据。我正在使用Rstudio用户界面。

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

数据的结构是:

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

dput()是:

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 个答案:

答案 0 :(得分:1)

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

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

取决于你想做什么