First two are going to not work, since you are looking for the index of max,
which is just a numeric value - i.e. index(1). The second is getting you the
index, but as a numeric - that is just a behavior of sapply in R.

The last examples (the ones from the site) are working for me under the
R-forge version, which is probably due for a push to CRAN.  The delay has
been in the process of getting some of the C back (up?) ported
to zoo - as now the dependency is a bit tighter.

Best,
Jeff


On Tue, Aug 2, 2011 at 12:42 PM, G See <gsee000@gmail.com> wrote:

> Well, one would think so, but it's not working out quite like I expected
>
> > period.apply(Cl(SPY), endpoints(SPY,"months"), FUN=function(x)
> index(max(x)))
>           SPY.Close
> 2011-01-31         1
> 2011-02-28         1
> 2011-03-31         1
> 2011-04-29         1
> 2011-05-31         1
> 2011-06-30         1
> 2011-07-29         1
> 2011-08-01         1
> > period.apply(Cl(SPY), endpoints(SPY,"months"), FUN=function(x)
> index(x[which.max(x)]))
>           SPY.Close
> 2011-01-31     15001
> 2011-02-28     15023
> 2011-03-31     15036
> 2011-04-29     15093
> 2011-05-31     15096
> 2011-06-30     15155
> 2011-07-29     15162
> 2011-08-01     15187
> >
>
> Also, the Apply by Period examples at
> http://www.quantmod.com/examples/data/ aren't
> working for me
> > endpoints(GS,on="months")
> >
> > # find the maximum closing price each week
> > apply.weekly(GS,FUN=function(x) { max(Cl(x)) } )
> >
> > # the same thing - only more general
> > period.apply(GS,endpoints(GS,on='weeks'),
> + FUN=function(x) { max(Cl(x)) } )
> >
> > # same thing - only 50x faster!
> > as.numeric(period.max(Cl(GS),endpoints(GS,on='weeks')))
>
> When I run the 1st 2, I get:
>
> > apply.weekly(GS,FUN=function(x) { max(Cl(x)) } )
> Error in dimnames(x) <- dn :
>  length of 'dimnames' [2] not equal to array extent
> > # the same thing - only more general
> > period.apply(GS,endpoints(GS,on='weeks'), FUN=function(x) { max(Cl(x)) }
> )
> Error in dimnames(x) <- dn :
>  length of 'dimnames' [2] not equal to array extent
>
>
> > sessionInfo()
> R version 2.13.1 (2011-07-08)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
>  [1] gsee_1.0                  qmao_1.0
>  [3] twsInstrument_1.0         quantmod_0.3-16
>  [5] TTR_0.20-3                Defaults_1.1-1
>  [7] FinancialInstrument_0.4.2 IBrokers_0.9-1
>  [9] xts_0.8-0                 zoo_1.7-2
>
> loaded via a namespace (and not attached):
> [1] grid_2.13.1     lattice_0.19-30 tools_2.13.1
> >
>
>
>
> 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.
> >
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> 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]]

