[R] Including time in a zoo

Horace Tso Horace.Tso at pgn.com
Tue Oct 10 23:19:24 CEST 2006


dear list,

I have these hourly price data over a 20 year period. Among other things, I want to plot them with time on the x-axis. The data is in a data frame,

> head(OWI.SE.all)
   Record_Number               Name Condition      Time_Period    Price
13            12 WECC-OWI SouthEast       All 1/1/2012 Hour: 1 41.21383
28            27 WECC-OWI SouthEast       All 1/1/2012 Hour: 2 38.38091
43            42 WECC-OWI SouthEast       All 1/1/2012 Hour: 3 39.97879
58            57 WECC-OWI SouthEast       All 1/1/2012 Hour: 4 40.14156
73            72 WECC-OWI SouthEast       All 1/1/2012 Hour: 5 38.21092
88            87 WECC-OWI SouthEast       All 1/1/2012 Hour: 6 40.09152

And the date-times are in a POSIX object dte1,

> class(dte1)
[1] "POSIXt"  "POSIXlt"

When I tried to create a zoo with dte1 as the index, I got an error,

> zoo(OWI.SE.all, dte1) 
Error in order(x, ..., na.last = na.last, decreasing = decreasing) : 
        unimplemented type 'list' in 'orderVector1'

I guess that's saying the index of a zoo can't have a time component. Am I correct? If so, is there a way to include an hour component in a zoo object.

Second question: 

If I just attach this dte1 to my data frame as a column named Date and try plotting it as,

> plot(OWI.SE.all$Date, OWI.SE.all$Price, type="l")

I got non-sensical result. How do I plot hourly data in general? 

TIA.

Horace W. Tso



More information about the R-help mailing list