align_dates: Aligns Date and Time Data Based on Official Station Records

View source: R/align_dates.R

align_datesR Documentation

Aligns Date and Time Data Based on Official Station Records

Description

This function compares date and time data from a user-provided dataframe ('df') against an official record stored in a CSV file. It checks if the date-time for each station in the input dataframe matches the expected values from the official record, based on station, year, and season. The function attempts to correct mismatches where possible and reports any discrepancies. It updates the 'date_time' column in the input dataframe where necessary and provides messages about the status of each match.

Usage

align_dates(df)

Arguments

df

A dataframe containing station data with a 'date_time' column. The dataframe must include a 'station' column to match against the official record.

Details

The function performs the following steps: 1. Loads an official record CSV containing expected station data. 2. Adds 'year_date_time' and 'season_date_time' columns to the input dataframe ('df') and the official record using the 'lubridate' package and the 'infer_season' function. 3. Compares the 'date_time' column from 'df' to the official record, checking for matches by station, year, and season. 4. For each row, it outputs a message describing the match status (e.g., no match, partial match, or full match). 5. Updates the 'date_time' column in the input dataframe if a mismatch is found and a valid correction is possible. 6. Returns the updated dataframe with corrected date-time values.

Value

A dataframe with the same structure as the input dataframe ('df'), but with updated 'date_time' values where mismatches are corrected. The columns 'year_date_time' and 'season_date_time' are removed from the output.

Examples

# Assuming 'df' is a dataframe with a 'station' and 'date_time' column
aligned_df <- align_dates(df)


BLE-LTER/BLE-LTER-utils documentation built on Jan. 5, 2025, 5:38 p.m.