[R-SIG-Finance] as.xts of a data.frame

Gabor Grothendieck ggrothendieck at gmail.com
Mon Apr 6 22:58:44 CEST 2009


Try this:

> Lines <- "Date,Open,High,Low,Close
+ 2003-07-25 01:00:00,1.61,1.61,1.61,1.61
+ 2003-07-25 02:00:00,1.61,1.61,1.61,1.61"
> library(xts)
> z <- read.zoo(textConnection(Lines), header = TRUE, sep = ",", tz = "")
> as.xts(z)
                    Open High  Low Close
2003-07-25 01:00:00 1.61 1.61 1.61  1.61
2003-07-25 02:00:00 1.61 1.61 1.61  1.61


On Mon, Apr 6, 2009 at 4:51 PM, Sebastian Hauer
<sebastian.hauer at gmail.com> wrote:
> Hello,
> I am trying to use quantmod to chart some of my existing OHLC data
> which I've loaded into my R session from a CSV file.
>
>> str(gbpusd)
> 'data.frame':   34361 obs. of  5 variables:
>  $ Tm: POSIXct, format: "2003-07-25 01:00:00" "2003-07-25 02:00:00" ...
>  $ Op: num  1.61 1.61 1.61 1.62 1.62 ...
>  $ Hi: num  1.61 1.61 1.62 1.62 1.62 ...
>  $ Lo: num  1.61 1.61 1.61 1.62 1.62 ...
>  $ Cl: num  1.61 1.61 1.62 1.62 1.62 ...
>
> But I am having a bit of a hard time coercing it from a data.frame into an xts.
>
>> as.xts(gbpusd)
> Error in as.POSIXlt.character(x, tz, ...) :
>  character string is not in a standard unambiguous format
>
> Or if I try it this way:
>
>> as.xts(gbpusd$Tm, gbpusd)
> Data:
> numeric(0)
> Index:
>  POSIXct[1:34361], format: "2003-07-25 01:00:00" "2003-07-25 02:00:00" ...
>
>
> Can anyone help me and explain what I am doing wrong, I would greatly
> appreciated it.
>
> Thanks,
> Sebastian
>
> _______________________________________________
> 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