XTS apply function to time of day subset?

后端 未结 1 413
暖寄归人
暖寄归人 2021-01-14 15:46

How can I apply a summary function to a time of day subset?

For example with:

r[\'T16:00/T17:00\']$Value

How can I apply something like

1条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-14 15:58

    You can use apply.daily to apply a function to each day's data after you've done the time-of-day subset.

    rt <- r['T16:00/T17:00','Value']
    rd <- apply.daily(rt, function(x) xts(t(quantile(x,0.9)), end(x)))
    

    You can see I needed to do a few backflips to ensure the object returned from your function can be handled by apply.daily. Mainly, it has to be a multi-column xts object with one row.

    0 讨论(0)
提交回复
热议问题