tags:

views:

56

answers:

2

Hi,

I try am trying to use the "to.minutes3" function in the xts package to segment my data.

This function does correctly put the time column into the desired intervals. But data columns becomes "open" , "close", "high" and "low". Is there are way tell the function to average the data points that fall into the same interval?

Thanks, Derek

+1  A: 

It looks to me like the answer is no, without completely changing that function, based on help("to.period"). to.minutes uses to.period, which says the following w.r.t. the OHLC parameter:

OHLC should an OHLC object be returned? (only OHLC=TRUE currently supported)

So other return values aren't supported.

Shane
+2  A: 

You want period.apply. Assuming your data are in object x and are more frequent than 3-minutes, the code below will give you a mean for each distinct, non-overlapping, 3-minute interval.

> period.apply(x, endpoints(x,k=3,"minutes"), mean)
Joshua Ulrich