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

Sebastian Hauer sebastian.hauer at gmail.com
Mon Apr 6 22:51:43 CEST 2009


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



More information about the R-SIG-Finance mailing list