prepare_geoclim: Prepare dekad or pentad data in GeoCLIM format

View source: R/prepare_geoclim.R

prepare_geoclimR Documentation

Prepare dekad or pentad data in GeoCLIM format

Description

prepare_geoclim rearranges a data frame to a format suitable for use in GeoCLIM. This data frame can be rearranged and exported to a file or connection with export_geoclim.

Usage

prepare_geoclim(
  data,
  year,
  type_col,
  element,
  station_id,
  latitude,
  longitude,
  type = c("dekad", "pentad"),
  metadata = NULL,
  join_by = NULL,
  add_cols = NULL
)

Arguments

data

data.frame The data.frame to calculate from.

year

character(1) The name of the year column in data.

type_col

character(1) The name of the dekad or pentad column in data.

element

character(1) The name of the element column in data to apply the function to.

station_id

character(1) The name of the station column in metadata, or data if metadata = NULL.

latitude

character(1) The name of the latitude column in metadata, or data if metadata = NULL.

longitude

character(1) The name of the longitude column in metadata, or data if metadata = NULL.

type

character(1) Whether the data is in dekad or pentad format.

metadata

data.frame The metadata data.frame to calculate from.

join_by

character The variable(s) to merge the data and metadata data frames.

add_cols

character Names of additional metadata columns that should be included in the output

Value

A data.frame formatted for use in GeoCLIM

Examples

# Calculate dekadal summaries for the rainfall column
dekad_data <- daily_niger %>% dplyr::mutate(dekad = dekad(date))
summary_data <- dekad_data %>% dplyr::group_by(station_name, year, dekad) %>%
      dplyr::summarise(mean_rain = mean(rain, na.rm = TRUE))
prepare_geoclim(data = summary_data, year = "year",
                station_id = "station_name",
                type_col = "dekad",
                element = "mean_rain", metadata = stations_niger, 
                join_by = "station_name",
                latitude = "lat", longitude = "long")

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