[R] zoo.read intraday data

Achim Zeileis Achim.Zeileis at uibk.ac.at
Mon Oct 25 15:31:45 CEST 2010


On Mon, 25 Oct 2010, Immanuel wrote:

> Hello all,
>
> I'm trying to use zoo.read

Just for the record: read.zoo().

> but can't figure out
> how to deal with the time format. (example below)

Yes, the problem is only the chron conversion (and not read.zoo).

> would be nice if someone could help.
>
> best regards,
> Immanuel
>
> ---------------------------
> L <- "Date,Time,Open,High,Low,Close,Up,Down
>        05.02.2001,00:30,421.20,421.20,421.20,421.20,11,0
>        05.02.2001,01:30,421.20,421.40,421.20,421.40,7,0
>        05.02.2001,02:00,421.30,421.30,421.30,421.30,0,5
>        05.02.2001,02:30,421.60,421.60,421.50,421.50,26,1"
>
> library(zoo)
> library(chron)
>
> f <- function(x) chron(paste(x[,1]),paste(x[,2]), format
>                    = c(dates = "D.M.Y", times = "hh:mm"))

I think that "chron" might require seconds. Hence you can add 00 seconds 
for all times and change the format accordingly, e.g.,

f <- function(x) chron(paste(x[,1]), paste(x[,2], "00", sep = ":"),
   format = c(dates = "d.m.y", times = "h:m:s"))

Then, the call below should work ok.

hth,
Z

> z <- read.zoo(textConnection(L), index = 1:2, sep=",", header = TRUE,
> FUN  = f)
>
> print(z)
>
> ______________________________________________
> 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