Skip to content
Prev 6711 / 15274 Next

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

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))