Extracting nth day of monthly data in r

倾然丶 夕夏残阳落幕 提交于 2019-12-02 05:48:34

You could create a list and store the subset for each day in a list. It might be useful when the number of rows are not the same for each day.

days <- unique(.indexmday(ask))
lst <- vector('list', length(days))
for(i in seq_along(days))lst[[i]] <- ask[.indexmday(ask)==days[i]]

sapply(lst, nrow)
# [1] 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400
#[13] 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400
#[25] 86400 86400 86400 86400 86400 14400

data

val <- rnorm(840000*3, 110)
indx <- seq(as.POSIXct('2014-09-01 00:00:00', format='%Y-%m-%d %H:%M:%S'),
    length.out=840000*3, by='sec')
library(xts)
ask <- xts(val, order.by=indx)
Joshua Ulrich

It seems like you want split.xts. Using the data from akrun's answer:

lst <- split(ask, "days")
sapply(lst, nrow)
# [1] 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400
#[13] 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400 86400
#[25] 86400 86400 86400 86400 86400 14400
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!