annual_max: Compute Annual Maximum and Mean of On-the-Hour Records

View source: R/loopFuns.R

annual_maxR Documentation

Compute Annual Maximum and Mean of On-the-Hour Records

Description

annual_max() takes a data frame of daily (or sub-daily) observations and returns a summary of the annual maximum and mean values, the date/time of each annual maximum, and the fraction of "on-the-hour" samples (data completeness) for each calendar year.

Usage

annual_max(DF, record_attribute = "sea_level")

Arguments

DF

A data.frame containing at least:

  • date: a Date or POSIXlt column of observation timestamps

  • a numeric column of values

record_attribute

A character string giving the name of the column in DF containing the values. Defaults to "sea_level".

Details

For each year, only observations exactly on the hour (minute == 0 & second == 0) are counted toward completeness. If no valid data exist for a year, that year is dropped from the output.

Value

a data.frame containing a date column and a numeric column (specified in record_attribute) for years where at least one nonNA value is present, containing:

  • annMax - the annual maximum

  • annMean - the annual mean (calendar year)

  • datestr - the date/time of the annual maximum, formatted "YYYYmmddHH"

  • date - the POSIXlt timestamp of the annual maximum

  • pc_complete - the fraction (0 to 1) of hourly-timestamped samples available in that year

Examples

# generate example daily data
dates <- seq.Date(as.Date("1990-01-01"), as.Date("1995-12-31"), by = "day")
DF <- data.frame(
  date      = dates,
  sea_level = rnorm(length(dates), mean = 0, sd = 1)
)
# compute annual summary
am <- annual_max(DF)
head(am)


loopevd documentation built on June 23, 2025, 5:09 p.m.