Hour aggregation function.

Share:

Description

This function allows for the aggregation of non-continuos time series data into hours from the first observation. It allows for the multiple hours to be specified. The aggregation method is also allowed to be set by the user.

Usage

1
hoursAgg(data, process, multiple = 1, na.rm = FALSE,tz="GMT")

Arguments

data

A timeSeries formatted dataset.

process

An aggregation method. See aggregate.

multiple

An integer specifying the aggregation block.

na.rm

Default is na.rm=FALSE

tz

A character string specifying the time zone to be used. If not specified the system tz may be used. This is different on each OS, therefore it is recommended that this is supplied. Default is GMT.

Details

This function is based on the aggregate method. It is designed to simplify the process of aggregating non-continuos data.

Value

Returns a data.frame with dates formatted as as.POSIXlt and aggregated data.

Author(s)

Jason Lessels <jason.lessels@sydney.edu.au>

See Also

aggregate

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
##Load the data
data(foo)
##Format the data using the timeSeries function.
foo.ts<-timeSeries(foo[,1],"%d/%m/%Y   %H:%M",foo[,3])
##Aggregate the data into hours using mean
hoursAgg(foo.ts,mean)
##Aggregate the data into 12 hour blocks using min
hoursAgg(foo.ts,mean,12)

##Load data with incomplete observations
data(foo.na)
##Format the data using the timeSeries function.
foo.na.ts <- timeSeries(foo.na[,1],"%d/%m/%Y   %H:%M",foo.na[,3])
##Aggregate the data into 30 hour blocks using mean
foo.na.1hr <- hoursAgg(foo.na.ts,mean,30,na.rm=TRUE)
##Aggregate the data into hours using mean
#foo.na.1hr <- hoursAgg(foo.na.ts,max,na.rm=TRUE)
# This will cause errors. Therefore a better approach 
# would be to subset the data.
foo.na.ts <-subset(foo.na.ts,!(is.na(foo.na.ts$data)))
##Try again without NA's
foo.na.1hr <- hoursAgg(foo.na.ts,max,na.rm=TRUE)