I have an xts numeric matrix that includes multiple days of minute interval series. I need to calculate statistics for each day on the minute periods, add new columns, and then put all the day series back together.
I have tried apply.daily(), which calls my stats function with an xts matrix, for each day, but I can’t figure how to return the modified day series back to the invoking function and reassemble the full set of modified data.
One solution that could work is to use endpoints(x, on = “day”) in a loop, then call rbind to reassemble the processed day frames. Is there a better solution?
process = function(myxts) {
day.indexes = endpoints(myxts, on="days")
days = length(day.indexes) - 1
l = list()
list.index = 1
for( i in 1:days ) {
day.begin = day.indexes[i] + 1
day.end = day.indexes[i+1]
l[[list.index]] = ets.sym.process.daily(myxts[day.begin:day.end])
list.index = list.index + 1
}
return(do.call("rbind", l))
}
You should be able to use some combination of
do.call(rbind, lapply(split(myxts,"days"), myfun)). It’s hard to be more specific without a reproducible example.