On Mon, Oct 25, 2010 at 11:44 AM, Immanuel <mane.d...@googlemail.com> wrote: > Thanks, > > by now I ran already into the next problem, while trying to convert > the zoo to an xts object. > Somehow the timestamps get lost, no idea why. > > I did read through the vignettes, but got confused > by all this, chron, as.POSIXct, zoo and xts stuff. > > with your example I got: > Error in .subset(x, j) : invalid subscript type 'list' > > > best regards > ------------------------- > > # TODO: Add comment > # > # Author: flyingimmi > ############################################################################### > > > 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 > 06.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], "00", sep = ":"), > format = c(dates = "d.m.y", times = "h:m:s")) > > > # z <- read.zoo("myfile.csv", index = 1:2, sep=",", header = TRUE, FUN = f) > > z <- read.zoo(textConnection(L), index = 1:2, sep=",", header = TRUE, > FUN = f) > > intradayData <- xts(z, time(z)) > > > print(z) > > print(intradayData) > --------------------------------------------------- > output: > > Open High Low Close Up Down > (05.02.01 00:30:00) 421.2 421.2 421.2 421.2 11 0 > (05.02.01 01:30:00) 421.2 421.4 421.2 421.4 7 0 > (05.02.01 02:30:00) 421.6 421.6 421.5 421.5 26 1 > (06.02.01 02:00:00) 421.3 421.3 421.3 421.3 0 5 > Open High Low Close Up Down > <NA> 421.2 421.2 421.2 421.2 11 0 > <NA> 421.2 421.4 421.2 421.4 7 0 > <NA> 421.6 421.6 421.5 421.5 26 1 > <NA> 421.3 421.3 421.3 421.3 0 5 >
I don't think xts supports chron. Try using POSIXct instead: f3 <- function(...) as.POSIXct(paste(...), format = "%d.%m.%Y %H:%M") z3 <- read.zoo(textConnection(L), index = list(1, 2), sep=",", header = TRUE, FUN = f3) as.xts(z3) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@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.