0

I have the following data:

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)

But when I try to plot the time series, I get:

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

How can I fix this? I somehow believe that the POSIXlt class is not correct, but if I change it to as.Date then I lose hours and minutes which are essential for this problem.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
Oniropolo
  • 879
  • 2
  • 12
  • 18
  • Try `with(feb2007, xts(V10, order.by = V2))`. –  Feb 18 '15 at 05:17
  • Wow, thank you! I have one more question, I have 2 time series, one for 2006, one for 2007, if I use rbind (), can I stack them up without fear of loosing information???? – Oniropolo Feb 18 '15 at 05:21
  • Oh no @Pascal This gives me another problem. Please see the question. – Oniropolo Feb 18 '15 at 05:23
  • 1
    What do you mean by "loosing information". By the way, the more simple is to try and if you are facing a problem, ask a new question with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). –  Feb 18 '15 at 05:24
  • True, I apologize. But now that I am plotting the time series I think there is an error somehow that I dont understand – Oniropolo Feb 18 '15 at 05:27
  • Please provide a `dput(head(feb2007, 20))`. –  Feb 18 '15 at 05:34
  • `plot(x)` works fine for me. –  Feb 18 '15 at 05:52
  • It returns me > plot(x) Error in as.POSIXlt.POSIXct(.POSIXct(.index(x)), tz = indexTZ(x)) : invalid 'tz' value – Oniropolo Feb 18 '15 at 05:53
  • Please start a clean session of R, load `xts` library and use your `dput()` to create `x`. Do you still have this error message? –  Feb 18 '15 at 06:00
  • Yes, I re-did everything. Same error. Is there any way of not using POSIXct ? – Oniropolo Feb 18 '15 at 06:13
  • I didn't pay attention, but V10 is a character vector. It should be numeric. –  Feb 18 '15 at 06:22
  • I changed it....Suddenly all the times became NA. let me update the question – Oniropolo Feb 18 '15 at 06:27
  • No, not the name, the content. –  Feb 18 '15 at 06:29
  • I added more information. I changed the column names and all the dates disappeared, so I changed it back and verified that the colums V10 V12 are numeric – Oniropolo Feb 18 '15 at 06:39
  • As @Pascal said, please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that illustrates your problem. I've edited your question to make it reproducible, but I do not get the error you say you receive. – Joshua Ulrich Feb 18 '15 at 11:06

0 Answers0