pad_to_year: Pads data to complete year

View source: R/pad.R

pad_to_yearR Documentation

Pads data to complete year

Description

Generic padding function. Generates a sequence from lubridate::floor(start_date, "year") to lubridate::ceil(end_date, "year"). The last point is excluded if end_date != max(data[[date_col]]). Under the hood the heavy lifting is done by tidyr::complete().

Usage

pad_to_year(
  data,
  date_col,
  interval,
  fill = list(),
  start_date = NULL,
  end_date = NULL
)

Arguments

data

input data

date_col

column containing date information, every date should be unique

interval

interval between two dates

fill

A named list that for each variable supplies a single value to use instead of NA for missing combinations.

start_date

optional start_date instead of min(data[[date_col]])

end_date

optional start_date instead of max(data[[date_col]])

Value

padded data

Examples

fn <- rOstluft.data::f("Zch_Stampfenbachstrasse_min30_2013_Jan.csv")
data <- rOstluft::read_airmo_csv(fn)
data <- rOstluft::rolf_to_openair(data)

# last data point is at 2013-01-31 23:30:00
tail(data)

# the site column get filled with NA, this could lead to problems
tail(pad_to_year(data, date, "30 min"))

# better to provide a fill value, for more complex cases use pad_to_year_fill()
tail(pad_to_year(data, date, "30 min", fill = list(site = "Zch_Stampfenbachstrasse")))

Ostluft/rOstluft.plot documentation built on Jan. 26, 2025, 1:05 a.m.