xts time series in R I have come across the
to.period() function that converts an OHLC or univariate object to a specified periodicity lower than the given data object.
I'm trying to understand how it aggregates the values to new values in the lower periodicity, I believed it to be the mean but that does not seem correct having calculated the value myself using the mean for that same period the results are different.
So what is the underlying function?
Here is an example that shows the different results:
data(sample_matrix) samplexts <- as.xts(sample_matrix) # Sample data contains OHLC values but I'm setting OHLC to False # I believe that is irrelevant for the purpose of the question to.period(samplexts["2007-06"], period = "months", OHLC = F ) Open High Low Close 2007-06-30 47.67468 47.94127 47.67468 47.76719 # I would have expected same values if applied the mean func # but values are different from above unlist(lapply(samplexts["2007-06"], mean)) Open High Low Close 47.47717 47.57592 47.38255 47.46899