This function processes a dataset by filling in missing values for specific parameters using data from a Ferrybox dataset. It rounds the timestamp to a specified unit, joins the Ferrybox data based on the rounded timestamp, and fills in missing values using the corresponding Ferrybox data.
Arguments
- data
A data frame containing the main dataset with a
timestampcolumn and several parameter columns that might have missing data.- ferrybox_data
A data frame containing the Ferrybox dataset. This dataset should have a
timestampcolumn and columns corresponding to the parameters specified.- parameters
A character vector of column names (parameters) in
datathat should be checked for missing values and potentially filled using the Ferrybox data.- rounding_function
A function that rounds the
timestampto a specified unit (e.g., minute). This function should take atimestampcolumn and aunitargument.
Value
A data frame similar to data, but with missing values in the specified parameters filled in using the Ferrybox data. The output includes only the timestamp and the specified parameter columns.
Details
The function performs the following steps:
Renames the columns in the
ferrybox_databy appending_ferryboxto the names of the specified parameters.Filters the
datafor rows with missing values in any of the specified parameters.Rounds the
timestampto the nearest specified unit using therounding_function.Joins the
ferrybox_datato the maindatabased on the roundedtimestamp.Uses the
coalescefunction to fill in missing values in the specified parameters with the corresponding values from the Ferrybox data.Returns a cleaned dataset containing only the
timestampand the specified parameter columns.
Examples
if (FALSE) { # \dontrun{
# Assuming you have a data frame `data` with missing values, a Ferrybox data frame `ferrybox_data`,
# and a rounding function `round_timestamp`.
filled_data <- handle_missing_ferrybox_data(data,
ferrybox_data,
c("8002", "8003", "8172"),
round_timestamp)
} # }
