Learn R Programming

s2dv (version 2.1.0)

Season: Compute seasonal mean or other calculations

Description

Compute the seasonal mean (or other methods) on monthly time series along one dimension of a named multi-dimensional arrays. Partial season is not accounted.

Usage

Season(
  data,
  monini,
  moninf,
  monsup,
  time_dim = "ftime",
  method = mean,
  na.rm = TRUE,
  ncores = NULL
)

Value

An array with the same dimensions as data except along the 'time_dim' dimension, of which the length changes to the number of seasons.

Arguments

data

A named numeric array with at least one dimension 'time_dim'.

monini

An integer indicating what the first month of the time series is. It can be from 1 to 12.

moninf

An integer indicating the starting month of the seasonal calculation. It can be from 1 to 12.

monsup

An integer indicating the end month of the seasonal calculation. It can be from 1 to 12.

time_dim

A character string indicating the name of dimension along which the seasonal mean or other calculations are computed. The default value is 'ftime'.

method

An R function to be applied for seasonal calculation. For example, 'sum' can be used for total precipitation. The default value is mean.

na.rm

A logical value indicating whether to remove NA values along 'time_dim' when calculating climatology (TRUE) or return NA if there is NA along 'time_dim' (FALSE). The default value is TRUE.

ncores

An integer indicating the number of cores to use for parallel computation. The default value is NULL.

Examples

Run this code
set.seed(1)
dat1 <- array(rnorm(144 * 3), dim = c(member = 2, sdate = 2, ftime = 12*3, lon = 3))
res <- Season(data = dat1, monini = 1, moninf = 1, monsup = 2)
res <- Season(data = dat1, monini = 10, moninf = 12, monsup = 2)
dat2 <- dat1
set.seed(2)
na <- floor(runif(30, min = 1, max = 144 * 3))
dat2[na] <- NA
res <- Season(data = dat2, monini = 3, moninf = 1, monsup = 2)
res <- Season(data = dat2, monini = 3, moninf = 1, monsup = 2, na.rm = FALSE)

Run the code above in your browser using DataLab