[R-SIG-Finance] applying to.period on matrices

Gabor Grothendieck ggrothendieck at gmail.com
Wed Feb 27 15:51:06 CET 2008


apply is not a generic function with class-specific methods.  Try this:

do.call(cbind, lapply(as.list(xts.ts), to.weekly))


On Wed, Feb 27, 2008 at 9:26 AM, Murali Menon <feanor0 at hotmail.com> wrote:
>
> Folks,
>
> I understand that the to.weekly (etc.) functions work only on univariate series or OHLC objects, so I thought that the standard apply(x, 2, to.weekly) technique might work. Unfortunately, it doesn't. What am I doing wrong? Please advise.
>
> > xx <- matrix(rnorm(1000), ncol=10)> xts.ts <- xts(xx, as.Date(13514:13613), origin="1970-01-01")> is.xts(xts.ts)[1] TRUE> to.weekly(xts.ts)Error in to.period(x, "weeks", name = name, ...) :   'x' must be a single column or an OHLC type object> apply(xts.ts, 2, to.weekly)Error in UseMethod("as.xts") : no applicable method for "as.xts"
> I'm guessing that the individual columns of the xts.ts object are not themselves xts objects? The index info is lost?
>
> I'm using R2.6.1 on Windows XP, and xts_0.0-10,  zoo_1.4-1
>
> Thanks,
>
> Murali
> _________________________________________________________________
> Climb to the top of the charts! Play the word scramble challenge with star power.
>
>        [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list