Monthly aggregation function

Share:

Description

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

Usage

1
monthsAgg(data, process, multiple = NULL, na.rm = FALSE)

Arguments

data

A timeSeries formatted dataset.

process

An aggregation method. See aggregate.

multiple

An integer specifying the aggregation block. Default is multiple=NULL.

na.rm

Default is na.rm=FALSE

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
##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 6 month blocks using mins
min.month <- monthsAgg(foo.ts,min,6)
##Aggregate the data into 6 days blocks using max
max.month <- monthsAgg(foo.ts,max,6)
##Aggregate the data into 6 days blocks using max
mean.month <- monthsAgg(foo.ts,mean,6)
#Create a plot of the results
ymin=min(min.month$data);ymax=max(max.month$data)
plot(mean.month,ylim=c(ymin,ymax))
lines(min.month,type="l",lty=3,col="red")
lines(max.month,type="l",lty=3,col="blue")