prepare_cdt: Prepare data in format for CDT

View source: R/prepare_cdt.R

prepare_cdtR Documentation

Prepare data in format for CDT

Description

prepare_cdt rearranges a data frame to a format suitable for use in CDT. This data frame can be rearranged and exported to a file or connection with export_CDT.

Usage

prepare_cdt(
  data,
  station,
  element,
  latitude,
  longitude,
  altitude,
  type = c("dekad", "daily"),
  date_time = NULL,
  year = NULL,
  month = NULL,
  dekad = NULL,
  metadata = NULL
)

Arguments

data

data.frame data.frame of daily or dekadal climatic data in tidy format i.e. one row per time point (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.

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.

type

character(1) Character indicating the type of data, either "dekad" or "daily".

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.

Value

A data.frame formatted for use in CDT

Examples

# Create summary daily data
data("daily_niger"); data("stations_niger")
cdt_data <- prepare_cdt(data = daily_niger, station = "station_name", element = "rain",
                        type = "daily", date_time = "date", latitude = "lat",
                        longitude = "long", altitude = "alt", metadata = stations_niger)

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