aggregate_with_criteria: Calculate an aggregated value taking into account certain...

View source: R/aggregation.R

aggregate_with_criteriaR Documentation

Calculate an aggregated value taking into account certain exclusion cirteria

Description

Often one needs to calulate the mean accepting certain number of missing values. For example, the World Meteorological Organisation specifies that monthly values must only be calculated if there is up to 10 missing days and less than 5 are consecutive. This function makes it easy to compute the monthly value by specifing these thresholds

Usage

aggregate_with_criteria(x, max_missing = 0, max_consecutive = 0,
  fun = mean)

mean_with_criteria(x, max_missing = 0, max_consecutive = 0)

min_with_criteria(x, max_missing = 0, max_consecutive = 0)

max_with_criteria(x, max_missing = 0, max_consecutive = 0)

sum_with_criteria(x, max_missing = 0, max_consecutive = 0)

Arguments

x

Numeric values

max_missing

Numeric. Maximum number or proportion of missing values in x. If any number of missing values is allowed set to 1 (100%) or NULL.

max_consecutive

Numeric. Maximum number or proportion of consecutive missing values in x. If any number of missing values is allowed set to 1 (100%) or NULL.

fun

Function. Function used to aggregate values usually, mean, min, max, or sum

Value

NA if the criteria arent meet the mean of x otherwise

Functions

  • mean_with_criteria: Mean with criteria

  • min_with_criteria: Minimum with criteria

  • max_with_criteria: Maximum with criteria

  • sum_with_criteria: Sum with criteria


StatisticsNZ/er.helpers documentation built on Oct. 2, 2023, 7:24 a.m.