# What is the underlying zoo's to.period aggregate function? [closed]

While studying 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

• It returns the closing value if you specify OHLC=FALSE, not the mean – Mohan Prashanth May 26 '17 at 14:01

to.period does not aggregate by using any function.

Here is what it does:

• As Open of the new monthly series: the Open of first day of the month of the daily series is used.

• As High of the new monthly series: The highest High of the month found in the daily series is used.

• As Low of the new monthly series: The lowest Low of the month found in the daily series is used.

• As Close of the new monthly series: the Close of last day of the month of the daily series is used.

Also, as per the help page:

only OHLC=TRUE currently supported