time_average: Create n-year averages of an NetCDF object

Description Usage Arguments Details Examples

View source: R/time_average.R

Description

This function computes n-year averages from an existing NetCDF time series read in with readNetCDF

Usage

1
time_average(x, n, offset = NULL, type = "start")

Arguments

x

array of class 'NetCDF'

n

number of time steps to average over

offset

offset from which to start (in years)

type

Alternative to specifying offset, one of start (the default), even or end, see details

Details

The automated way to set the offset works as following. start starts the n-year averages at the beginning of the time series, end sets the offset so that the last average ends in the last year of the time series, even sets the offset so that modulo(year, n) == 0 for the first year in the first average (i.e. for n=5 averages such as 1910-1914).

The time attribute reflects the average over the same block as the average of the data, that is n-yearly averages will be centered.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
tas <- readNetCDF(system.file("extdata", "annual_CRUTEMv3_1961-90.nc", package="geoutils"), varname="temp")

## compute 5-yearly averages
tas.avg <- time_average(tas, 5, type='start')

## get a grid point with little missing values
si <- which.max(apply(!is.na(tas), 1, sum))

## plot the data
plot(tas, type='ts', si=si, lwd=1)
plot(tas.avg, type='ts', si=si, col=2, lwd=2, add=T)

jonasbhend/geoutils documentation built on May 19, 2019, 7:27 p.m.