Taken from this stackoverflow question. period.apply() returns a matrix with one column per row when the function returns multiple rows per period. But it should return the same result as do.call(rbind, split(x, "[period"])). For example:
period.apply(x, "years", range) should return one row per endpoint, where index(output[i]) <- end(input[i]) with a column for each function output.
period.apply(x, years, cummax) should return an xts object with the same number of rows and columns as the input (because of cummax.xts() works by column).
period.apply(x, "years", rollapply, by.column = T/F) is a good test case. We'll always rbind() the rollapply() output if it's an xts object. How do we handle if it isn't an xts object?
period.apply() should always rbind() the result when FUN returns a 1-row matrix. The index should be set to the last index value in the period.
Taken from this stackoverflow question.
period.apply()
returns a matrix with one column per row when the function returns multiple rows per period. But it should return the same result asdo.call(rbind, split(x, "[period"]))
. For example:The result should have the same number of observations as the input,
x
.Scenarios to test:
period.apply(x, "years", range)
should return one row per endpoint, whereindex(output[i]) <- end(input[i])
with a column for each function output.period.apply(x, years, cummax)
should return an xts object with the same number of rows and columns as the input (because ofcummax.xts()
works by column).period.apply(x, "years", rollapply, by.column = T/F)
is a good test case. We'll alwaysrbind()
therollapply()
output if it's an xts object. How do we handle if it isn't an xts object?period.apply()
should alwaysrbind()
the result whenFUN
returns a 1-row matrix. The index should be set to the last index value in the period.