如何以多种方式拆分xts对象?

时间:2015-10-16 21:21:56

标签: r split xts

我有以下数据:

xtsdata <- structure(c(0.44696179, 0.395227931, 0.477439822, 0.295309508, 
  0.712614891, 0.689317114, 0.599395023, 0.610971864, 0.337625508, 0.529290134,
  0.596002106, 0.412324483, 0.244831259, 0.443123542, 0.484748065, 0.686165972,
  0.711764909, 0.604578061, 0.42144923, 0.669898641, 0.735845192, 0.592157589,
  0.81714156, 0.380346873, 0.684386001, 0.672967504, 0.508142689, 0.244274776,
  0.548213564, 0.417804342, 0.612475603, 0.665148957, 0.756447435, 0.582448567,
  1, 1, 1, 1, 1, 1, 0.71708817, 0.528262036, 0.597354154, 0.886971243, 0.624771744,
  0.498557661, 0.382554107, 0.464373083, 0.425888914, 0.747806533, 0.788271626,
  0.407617084, 0.784747938, 0.466987506, 0.554976586, 0.621751352, 0.501173993,
  0.323827823, 0.659625721, 0.502665703, 0.626577183, 0.458883576, 0.572507952,
  0.388946538, 0.897384403, 0.784054708, 0.652210478, 0.850226608, 0.514172118,
  0.780114865, 0.710307692, 0.714749488, 0.248817293, 0.576462902, 0.690210031),
  class = c("xts", "zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC",
  tzone = "UTC", index = structure(c(1288828800, 1288915200, 1289174400, 1289260800,
  1289347200, 1289433600, 1289520000, 1289779200, 1289865600, 1289952000,
  1290038400, 1290124800, 1290384000, 1290470400, 1290556800), tzone = "UTC",
  tclass = "Date"), .Dim = c(15L, 5L), .Dimnames = list(NULL, c("Stock1", "Stock10",
  "Stock100", "Stock101", "Stock102")))

我可以按周拆分:

xtslist <- split(xtsdata, f="weeks")

并输出5天的组列表。

我想知道的第一件事是如何使用splitsplit.xts函数来确定我自己的间隔(例如3)。

其次,我需要一个函数,它将使用10的窗口分割xtsdata,但间隔为5.因此列表中的第一个元素将包含前5个句点,第二个元素将包含0到10的句点,第三个元素将包含5到15期。

0 个答案:

没有答案