Skip to content

Time series in half hourly intervals- how do i do it?/

3 messages · Adrian Ladaniwskyj, Brian G. Peterson, Gabor Grothendieck

#
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
a time series object properly- I'm hoping someone can help me out here.

Cheers!

Adrian Ladaniwskyj | Market Analyst, Spot Tactics
B.Bus, B.Ec(Hons), Dip.FS 


p +61 3 6230 5495 | f +61 3 6230 5416 | m +61 431 121 711
e adrian.ladaniwskyj at hydro.com.au
w www.hydro.com.au
Level 9, 4 Elizabeth Street, Hobart TAS 7000
#
On Mon, 27 Sep 2010 17:21:47 +1000, "Adrian Ladaniwskyj"
<Adrian.Ladaniwskyj at hydro.com.au> wrote:
'thousands of points' hardly qualifies as vast amounts of data.

use xts with a POSIXct index.  It will solve your problem.  There are
plenty of examples in the list archives and the documentation that should
show you how.

If you're still having issues, please provide a reproducible example, per
the posting guide.

Regards,

    - Brian
#
On Mon, Sep 27, 2010 at 3:21 AM, Adrian Ladaniwskyj
<Adrian.Ladaniwskyj at hydro.com.au> wrote:
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))