prepare_cdt_dekad: Prepare data in format for CDT

View source: R/prepare_cdt_dekad.R

prepare_cdt_dekadR Documentation

Prepare data in format for CDT

Description

prepare_cdt_dekad takes a dekad data. This data is then rearranged to a format suitable for use in CDT. This data frame can be rearranged and exported to a file or connection with export_CDT_dekad.

Usage

prepare_cdt_dekad(
  data,
  station,
  element,
  date_time = NULL,
  year = NULL,
  month = NULL,
  dekad = NULL,
  metadata = NULL,
  latitude,
  longitude,
  altitude
)

Arguments

data

data.frame data.frame of dekadal climatic data in tidy format i.e. one row per dekad (per station) and one column per element.

station

character(1) Name of the station identifying column in data.

element

character(1) Name of the element column in data.

date_time

character(1) Name of the date column in data. Required if type = "daily". If type = "dekad" this is only needed if year, month, and dekad are not specified.

year

character(1) Name of the year column in data. Only needed if type = "dekad". If NULL it will be created using lubridate::year(data[[date_time]]).

month

character(1) Name of the month column in data. Only needed if type = "dekad". If NULL it will be created using lubridate::month(data[[date_time]]).

dekad

character(1) Name of the dekad column in data. Only needed if type = "dekad". If NULL it will be created using dekad function.

metadata

data.frame data.frame of station metadata. Use this is the station details are in a separate data.frame with one row per station. If specified, latitude, longitude and altitude are assumed to be in metadata and station must be in both data and metadata to facilitate joining.

latitude

character(1) Name of the latitude column in metadata.

longitude

character(1) Name of the longitude column in metadata.

altitude

character(1) Name of the altitude column in metadata.

Value

A data.frame formatted for use in CDT.

Examples

# Create prepare summary dekad data for CDT export
summary_data <- daily_niger %>%
                   dplyr::mutate(dekad_date = dekad(daily_niger$date)) %>%
                   dplyr::group_by(station_name, year, dekad_date) %>%
                   dplyr::summarise(date = dplyr::first(date), sum = sum(tmax))

prepare_cdt_dekad(data = summary_data, date_time = "date", year = "year",
                  station = "station_name",
                  element = "sum", metadata = stations_niger, 
                  latitude = "lat", longitude = "long", altitude = "alt")

IDEMSInternational/cdms.products documentation built on July 7, 2023, 10:13 a.m.