SRrun3: Three-Year Running Mean

View source: R/SRrun3.R

SRrun3R Documentation

Three-Year Running Mean

Description

Calculate the three-year moving average of a time series of data, by the specified grouping variables.

Usage

SRrun3(df, x, group, time, minfreq = 2)

Arguments

df

A data frame containing the data to be averaged.

x

A character scalar, naming the element of df with the numeric estimates to be averaged.

group

A character scalar, naming the element of df with the grouping variable.

time

A character scalar, naming the element of df with the numeric variable denoting time.

minfreq

A numeric scalar, the minimum number of non-missing observations required to calculate an average, default 2.

Value

A data frame with one row per group and time, giving the raw observations (Y) and their corresponding three-year running mean (Y.3mn).

Examples

rawdat <- data.frame(
  Year = 1990 + c(0:5, 8:9, 2:3, 5:8),
  Type = rep(1:2, c(8, 6)),
  Y = c(1:12, 9, 7)*10
)
SRrun3(rawdat, "Y", "Type", "Year", minfreq=1)
SRrun3(rawdat, "Y", "Type", "Year")
SRrun3(rawdat, "Y", "Type", "Year", minfreq=3)

JVAdams/GLFC documentation built on Jan. 5, 2023, 12:59 a.m.