[R-SIG-Finance] Time series in half hourly intervals- how do i do it?/

Gabor Grothendieck ggrothendieck at gmail.com
Mon Sep 27 14:40:17 CEST 2010


On Mon, Sep 27, 2010 at 3:21 AM, Adrian Ladaniwskyj
<Adrian.Ladaniwskyj at hydro.com.au> wrote:
>
>
> Hi all;
>
> I'm working on a half hourly interval time series that looks like so:
>
>
> a)
> iteration         Datetime    VIC1    NSW1     SA1    QLD1
> 1         1 2011-01-01 00:30 5482.09 7670.81 2316.22 5465.13
> 2         1 2011-01-01 01:00 5178.33 7474.04 2130.30 5218.61
> 3         1 2011-01-01 01:30 4975.51 7163.73 2042.39 5058.19
> 4         1 2011-01-01 02:00 5295.36 6850.14 1940.19 4897.96
> 5         1 2011-01-01 02:30 5042.64 6587.94 1836.19 4749.05
> 6         1 2011-01-01 03:00 4799.89 6388.51 1786.32 4672.92
>
>
> Because of the vast volume of data, thousands of points, I would like
> parse the table into a timeseries object, while keeping the date/time
> information like in table a) so when plotted, it's instantly
> recognisable which timeperiod it refers to, instead of "observation
> 500:700" etc etc.  (i.e. I want the human readable time/date to be on
> the x axis)
>
> Plotting extracts from b), below, just doesn't produce what I am looking
> for.
>
> b)
> datetime    VIC1a    NSW1a     SA1a    QLD1a
> [1,]        1 5812.712 7251.341 2293.058 5410.479
> [2,]        2 5495.955 7078.464 2108.997 5166.424
> [3,]        3 5291.423 6833.390 2021.966 5007.608
> [4,]        4 5622.505 6544.065 1920.788 4848.980
> [5,]        5 5347.363 6301.389 1817.828 4701.560
>
> From the help files, I can't figure out how to put half hourly data into
> a time series object properly- I'm hoping someone can help me out here.
>

Try this.  Since you only have 6 column headings but 8 columns we just
skip the header.  It seems that you don't need time zones so we used
as.chron but if you do you could replace as.chron with as.POSIXct.
The index is in columns 3 and 4 so we indicate such with the index
argument.  It then feeds the two columns into FUN which pastes them
together and feeds the output of FUN into FUN2 which converts it to
the appropriate datetime type.

L <- "iteration         Datetime    VIC1    NSW1     SA1    QLD1
1         1 2011-01-01 00:30 5482.09 7670.81 2316.22 5465.13
2         1 2011-01-01 01:00 5178.33 7474.04 2130.30 5218.61
3         1 2011-01-01 01:30 4975.51 7163.73 2042.39 5058.19
4         1 2011-01-01 02:00 5295.36 6850.14 1940.19 4897.96
5         1 2011-01-01 02:30 5042.64 6587.94 1836.19 4749.05
6         1 2011-01-01 03:00 4799.89 6388.51 1786.32 4672.92"

library(zoo)
library(chron)

# replace textConnection(L) with name of your file

z <- read.zoo(textConnection(L), skip = 1,
	FUN = paste, FUN2 = as.chron, index = list(3, 4))


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-SIG-Finance mailing list