An alternate approach is to use split, lapply, and rbind.  This is
leveraging the power of R and xts:


set.seed(109)
x <- xts(cumsum(rnorm(1000)), Sys.time()+1:1000)
do.call(rbind,lapply(split(x, 'minutes'), function(X) X[which.min(X)]))
do.call(rbind,lapply(split(x, 'minutes'), function(X) X[which.max(X)]))

Note that split is calling split.xts, which in turn calls endpoints. Of
course function could do whatever you like, instead of one at a time.

### output  ###

> x <- xts(cumsum(rnorm(1000)), Sys.time()+1:1000)
> do.call(rbind,lapply(split(x, 'minutes'), function(X) X[which.min(X)]))
                           [,1]
2011-08-02 12:32:39  -1.9583484
2011-08-02 12:33:08   3.7630720
2011-08-02 12:34:03   9.2894788
2011-08-02 12:35:43  -2.1770427
2011-08-02 12:36:55 -10.3794387
2011-08-02 12:37:27 -10.7580228
2011-08-02 12:38:39 -15.6854896
2011-08-02 12:39:01 -14.3843611
2011-08-02 12:40:14  -5.5693735
2011-08-02 12:41:26 -12.9454941
2011-08-02 12:42:19  -8.8814271
2011-08-02 12:43:02  -7.0712532
2011-08-02 12:44:09  -1.4857938
2011-08-02 12:45:16   4.4736098
2011-08-02 12:46:04   5.8614302
2011-08-02 12:47:56   1.0629393
2011-08-02 12:48:18   0.4441608
2011-08-02 12:49:14  -4.2264601
> do.call(rbind,lapply(split(x, 'minutes'), function(X) X[which.max(X)]))
                          [,1]
2011-08-02 12:32:56  4.4097681
2011-08-02 12:33:43 13.3658123
2011-08-02 12:34:26 26.2871633
2011-08-02 12:35:00 15.6440839
2011-08-02 12:36:16 11.8781900
2011-08-02 12:37:43 -1.0402466
2011-08-02 12:38:00 -2.4549683
2011-08-02 12:39:56  1.7925557
2011-08-02 12:40:00  1.7740082
2011-08-02 12:41:00 -2.4852176
2011-08-02 12:42:43 -0.7717046
2011-08-02 12:43:49  5.9443749
2011-08-02 12:44:52 10.6448586
2011-08-02 12:45:42 14.7971373
2011-08-02 12:46:22 11.6357134
2011-08-02 12:47:32 10.9959670
2011-08-02 12:48:41  6.6057782
2011-08-02 12:49:01  1.7507878


On Tue, Aug 2, 2011 at 12:29 PM, Brian G. Peterson <brian@braverock.com>wrote:

>
> On Tue, 2011-08-02 at 19:18 +0200, Ulrich Staudinger wrote:
> > Hi Noah,
> >
> > While I can't help you on the mean, I would like to use the opportunity
> to
> > raise a request for support to track when the high and the low occurred
> in a
> > bar, something like highTime and lowTime.
>
> As with Garrett's earlier reply for the mean, period.apply may be used
> to get the index of the value that made the high or low.
>
> Regards,
>
>   - Brian
>
> --
> Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
>
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>



-- 
Jeffrey Ryan
jeffrey.ryan@lemnica.com

www.lemnica.com
www.esotericR.com

	[[alternative HTML version deleted]]

