将带有日期的data.frame转换为xts时间序列

时间:2015-02-18 05:14:25

标签: r time-series xts

我有以下数据:

feb2007 <-
structure(list(V2 = structure(list(sec = c(0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = 0:19, hour = c(0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L), mday = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), mon = c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L), year = c(107L, 107L, 107L, 107L, 107L, 107L, 107L, 107L, 
107L, 107L, 107L, 107L, 107L, 107L, 107L, 107L, 107L, 107L, 107L, 
107L), wday = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), yday = c(31L, 31L, 31L, 31L, 
31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 
31L, 31L, 31L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), zone = c("EST", 
"EST", "EST", "EST", "EST", "EST", "EST", "EST", "EST", "EST", 
"EST", "EST", "EST", "EST", "EST", "EST", "EST", "EST", "EST", 
"EST"), gmtoff = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
NA_integer_)), .Names = c("sec", "min", "hour", "mday", "mon",      
"year", "wday", "yday", "isdst", "zone", "gmtoff"), class = c("POSIXlt", 
"POSIXt")), V10 = c("45", "45", "45", "45", "45", "45", "44", 
"45", "45", "45", "45", "45", "45", "45", "45", "45", "45", "46", 
"46", "46"), V12 = c("43", "43", "43", "43", "43", "42", "42", 
"42", "43", "43", "43", "43", "43", "43", "43", "43", "43", "43", 
"43", "43")), .Names = c("V2", "V10", "V12"), row.names = c(NA, 
20L), class = "data.frame")

feb2007$V12 <- as.numeric(feb2007$V12)
feb2007$V10 <- as.numeric(feb2007$V10)
x <- xts(feb2007$V2,feb2007$V10)

但是当我尝试绘制时间序列时,我得到了:

plot.xts(x)
# Error in as.POSIXlt.POSIXct(.POSIXct(.index(x)), tz = indexTZ(x)) : 
#   invalid 'tz' value

我该如何解决这个问题?我不知怎的相信POSIXlt类不正确,但是如果我把它改成as.Date那么我就会失去对这个问题至关重要的小时和分钟。

0 个答案:

没有答案