R 将数据帧转换为Zoo。Posixlt的问题

R 将数据帧转换为Zoo。Posixlt的问题,r,dataframe,zoo,R,Dataframe,Zoo,我试图将数据帧转换为zoo对象,但遇到了不少麻烦。无论我在read.zoo调用中做什么,我都会得到以下错误。我认为甚至没有必要列出时间戳的格式,因为它已经是Posixlt了,但事实并非如此 你能给我指一下正确的方向吗 Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format 这是一个数据样本 Date O

我试图将数据帧转换为zoo对象,但遇到了不少麻烦。无论我在read.zoo调用中做什么,我都会得到以下错误。我认为甚至没有必要列出时间戳的格式,因为它已经是Posixlt了,但事实并非如此

你能给我指一下正确的方向吗

Error in as.POSIXlt.character(x, tz, ...) : 
  character string is not in a standard unambiguous format
这是一个数据样本

                   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
以下是可复制代码:

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")
require(动物园)

数据假设在
数据之后立即调用以下内容不幸的是,
read.zoo
的当前限制是它不处理POSIXlt索引输入,但上面的答案,首先将其转换为POSIXct,似乎是一个好方法。另一种方法是先将其转换为字符:
read.zoo(transform(data,Date=format(Date)),tz=“”)
,谢谢你们的评论。它现在使用hrbrmstr的代码工作。我不准备让它忽略原生的R日期格式,文档中也没有明确说明。我认为把格式放在read.zoo调用中就足够了。我将继续考虑这个问题。Achim刚刚在开发版本中修复了它(现在可以通过subversion获得,最终将在CRAN上获得),因此通过该修复,这个问题可以工作:
read.zoo(data)
read.zoo( transform( data, Date = as.POSIXct(Date) ), FUN = identity )