date_clean: Clean dates in occurrence data sets

View source: R/date_clean.R

date_cleanR Documentation

Clean dates in occurrence data sets

Description

Parses dates with varying format into a consistent format of specified resolution (e.g., year, month, day) and removes problematic dates that cannot be parsed or do not match the specified resolution.

Usage

date_clean(data, date_col = "eventDate", date_res = "year")

Arguments

data

Data.frame of occurrence data set (e.g. MyCoPortal, GBIF)

date_col

Character string specifying the date column. Default is "eventDate" (i.e., the Darwin Core standard).

date_res

Character string specifying the desired resolution for parsed dates (i.e., "year", "month", "day"). Default is "year".

Value

Data.frame containing the input data set with the following output fields appended. Records with dates that could not be parsed or do not match the specified resolution are removed.

date_fixed

Variabe date formats are transformed into standard YYYY-MM-DD format. Dates limited to year or month resolution (e.g., 1990-00-00 or 1990-01-00), are transformed to YYYY (e.g., 1990) or YYYY-MM (e.g., 1990-01) format respectively.

parsed_format

Detected date format (e.g., "Y", "Ym", or "Ymd").

parsed_date

"date_fixed" values are parsed into standard POSIXct date-time objects using lubridate::parse_date_time

year_fixed

The collection year value after cleaning and parsing dates.

month_fixed

The collection month value after cleaning and parsing dates.

day_fixed

The collection day value after cleaning and parsing dates.

Note

Full dates other than the "Ymd" format are all assumed to be in the "dmY" format, not "mdY". Ex: 01/10/1990 is assumed to be October 10, 1990, not January 10, 1990.

Examples

library(fungarium)
data(agaricales_updated) #import sample data set
clean <- date_clean(agaricales_updated) #clean dates


hjsimpso/fungarium documentation built on Aug. 23, 2023, 3:59 p.m.