Reputation: 921
I am trying to convert a data frame to a zoo object and having quite a bit of trouble. No matter what I do in the read.zoo call I get the below error. I would think that it is not even necessary to list the format of the timestamp since it is already Posixlt but that is not the case.
Can you point me in the right direction?
Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format
This is a sample of the data,
Date Open High Low Close
330 2014-01-03 15:00:00 544.95 545.10 544.80 544.86
331 2014-01-03 15:01:00 544.80 544.89 544.77 544.79
332 2014-01-03 15:02:00 544.84 544.90 544.79 544.80
333 2014-01-03 15:03:00 544.80 544.80 544.60 544.69
334 2014-01-03 15:04:00 544.75 544.80 544.66 544.75
335 2014-01-03 15:05:00 544.78 545.03 544.76 545.01
Here is reproducible code:
require (zoo)
data <- structure(list(Date = structure(list(sec = c(0, 0, 0, 0, 0, 0
), min = 0:5, hour = c(15L, 15L, 15L, 15L, 15L, 15L), mday = c(3L,
3L, 3L, 3L, 3L, 3L), mon = c(0L, 0L, 0L, 0L, 0L, 0L), year = c(114L,
114L, 114L, 114L, 114L, 114L), wday = c(5L, 5L, 5L, 5L, 5L, 5L
), yday = c(2L, 2L, 2L, 2L, 2L, 2L), isdst = c(0L, 0L, 0L, 0L,
0L, 0L)), .Names = c("sec", "min", "hour", "mday", "mon", "year",
"wday", "yday", "isdst"), class = c("POSIXlt", "POSIXt")), Open = c(544.95,
544.8, 544.84, 544.8, 544.75, 544.78), High = c(545.1, 544.89,
544.9, 544.8, 544.8, 545.03), Low = c(544.8, 544.77, 544.79,
544.6, 544.66, 544.76), Close = c(544.86, 544.79, 544.8, 544.69,
544.75, 545.01)), .Names = c("Date", "Open", "High", "Low", "Close"
), row.names = 330:335, class = "data.frame")
data <- read.zoo(data, header = TRUE, index = 1, tz="", format = "%Y-%m-%d %H:%M:%S")
Upvotes: 1
Views: 516
Reputation: 78852
Assuming the following is called right after your data <- structure(…
read.zoo( transform( data, Date = as.POSIXct(Date) ), FUN = identity )
it should get you going in the right direction. A ?read.zoo
should help in the understanding of what that does.
Upvotes: 2