[R-SIG-Finance] [R-sig-finance] xts feature
jeff.a.ryan at gmail.com
Mon Jan 26 19:37:54 CET 2009
Yes grep will coerce the index with as.character. That method should
always work with xts though... and off the top of my head I can't
think of a (more) efficient way to accomplish this.
And you are correct, the period.apply would calculate the in-period
statistic (mean in this case) for each period, NOT the mean for all
observation with that time-stamp.
R/Finance 2009: Applied Finance with R
April 24, 25th Chicago, IL
On Mon, Jan 26, 2009 at 12:15 PM, <Murali.MENON at fortisinvestments.com> wrote:
> Hi Jeff,
> With that same dataset of Kafkaz's, if we wanted to compute the mean of
> all the 15:30:00 Volume datapoints (there are two here), how would we do
> it? The code you give below will perform the 'mean' operation on all
> data points falling within each hour, but separate them day-by-day, if
> that makes sense.
> Would I have to do something like
> mean(x[grep("15:30:00", index(x)), "Volume"])
> This works with a POSIXct index, but seems to assume that there is a
> character representation for the time index?
> -----Original Message-----
> From: r-sig-finance-bounces at stat.math.ethz.ch
> [mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Jeff Ryan
> Sent: 26 January 2009 17:31
> To: kafkaz
> Cc: r-sig-finance at stat.math.ethz.ch
> Subject: Re: [R-SIG-Finance] [R-sig-finance] xts feature
> Hi Kafkaz,
> Try something like:
> period.apply(Vo(x), endpoints(x, 'hours'), mean)
> Useful tools from xts that are of interest:
> ?period.apply, ?endpoints, ?to.period
> You can also use aggregate, which on xts objects will call the method
> from the zoo package (automatically loaded).
> R/Finance 2009: Applied Finance with R
> April 24, 25th Chicago, IL
> http://www.quantmod.com/news/ http://www.RinFinance.com
> Jeffrey Ryan
> jeffrey.ryan at insightalgo.com
> ia: insight algorithmics
> R-SIG-Finance at stat.math.ethz.ch mailing list
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
jeffrey.ryan at insightalgo.com
ia: insight algorithmics
More information about the R-SIG-Finance