export_geoclim_pentad: Export pentad data in GeoCLIM format

View source: R/export_geoclim_pentad.R

export_geoclim_pentadR Documentation

Export pentad data in GeoCLIM format

Description

export_geoclim_pentad takes a data frame that is in a pentad format. This data frame is then rearranged using prepare_geoclim_pentad to a format suitable for use in GeoCLIM, and then written to a file or connection.

Usage

export_geoclim_pentad(
  data,
  year,
  pentad,
  element,
  metadata = NULL,
  join_by = NULL,
  station_id,
  latitude,
  longitude,
  add_cols = NULL,
  file_path = paste0("GEOCLIM-", element, ".csv"),
  ...
)

Arguments

data

data.frame The data.frame to calculate from.

year

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

pentad

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

element

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

metadata

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

join_by

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

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.

add_cols

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

file_path

character(1) A character specifying the file path and file name to export.

...

Other parameters passed to write.csv()

Value

Invisibly returns the file path of the saved data.

Examples

# Calculate pentad summaries for the rainfall column
pentad_data <- daily_niger %>% dplyr::mutate(pentad = pentad(date))
# Summarise the data
summary_data <- pentad_data %>% dplyr::group_by(station_name, year, pentad) %>%
      dplyr::summarise(mean_rain = mean(rain, na.rm = TRUE))
# NOT RUN: Export the data to CSV format
#export_geoclim_pentad(data = summary_data, year = "year",
#                     station_id = "station_name",
#                     pentad = "pentad",
#                     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.