[R] How to combine Date and time in one column

Gabor Grothendieck ggrothendieck at gmail.com
Wed Nov 24 02:07:11 CET 2010


On Tue, Nov 23, 2010 at 7:56 PM, Nikos Rachmanis
<nikos.rachmanis at gmail.com> wrote:
> Hi Gabor,
> Thanks very much for the suggestion. It worked well until the point that i
> tried to plot the xts object. here is my code and the error message.
> lines<-data.frame(date,time,open,high, low,close) #create a dataframe with
> all the variables
> z <- read.zoo(lines, header = TRUE, index = list(1, 2), FUN = function(d, t)
> as.chron(paste(as.Date(chron(d)), t))) #create the zoo object
> plot(z) # works fine
> x<-as.xts(z) #works fine
> plot(x)
> Error in parse.format(format[1]) : unrecognized format %b %d %H:%M
> any ideas?
> Thanks!
>

Probably a bug plotting chron objects in xts.   Either pot it with zoo
or use POSIXct and plot it with xts:

plot(z$C)

#  or

z <- read.zoo(textConnection(Lines), header = TRUE, index = list(1, 2),
       FUN = function(...) as.POSIXct(paste(...), format = "%m/%d/%Y %H:%M"))
x <- as.xts(z)
plot(x)


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list