[R] xtable problems with xts objects

Ista Zahn istazahn at gmail.com
Wed Jul 30 23:50:58 CEST 2014


Hi Stergios,

I think as.data.frame(x) solves both your problems.

Best,
Ista



On Wed, Jul 30, 2014 at 5:22 PM, Stergios Marinopoulos
<stergios_marinopoulos at yahoo.com> wrote:
> Hi,  I'm having trouble getting xtable to print a simple xts object.  When the frequency is 1800 I get an error.  However when frequency(x) is reported as 1 it works.  I have included example below.
>
>
>
> Another question is how can I have the time index printed in place of the row number?
>
> Thanks for your help,
> --
> Stergios Marinopoulos
>
> library(xts)
> library(xtable)
>
> # This does not work.  The indices are 1800 seconds apart.
> x = xts(x=rep(pi, 6), order.by=as.POSIXlt( "2014-01-01 06:30:00" ) + 1800 * 0:5 )
>
> print(xtable(x))
> print(frequency(x))  # [1] 0.0005555556
>
> # This is the error message:
> # Error in rep(NA, start(x)[2] - 1) : invalid 'times' argument
>
>
> # It works when I make the indices only 1 second apart.
> x = xts(rep(pi, 6), as.POSIXlt( "1970-01-01 00:00:00" ) + 0:5 )
> print(xtable(x))
> print(frequency(x))  # [1] 1
>
>
> # Here is a daily data example that works.
> library(quantmod)
> AAPL = getSymbols("AAPL", auto.assign=FALSE, from="2014-01-01", to="2014-01-10")
> print(xtable(AAPL), include.rownames=TRUE)
> print(frequency(x))  # [1] 1
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list