Function checks the validity of each characteristic-media-result unit combination in the dataframe. When clean = "invalid_only", rows with invalid characteristic-media-result unit combinations are removed. Default is clean = "invalid_only". When flaggedonly = TRUE, dataframe is filtered to show only rows with "Invalid" or "NonStandardized" characteristic-media-result unit combinations. Default is flaggedonly = FALSE.
Usage
TADA_FlagResultUnit(
.data,
clean = c("invalid_only", "nonstandardized_only", "both", "none"),
flaggedonly = FALSE
)
Arguments
- .data
TADA dataframe
- clean
Character argument with options "invalid_only", "nonstandardized_only", "both", or "none." The default is clean = "invalid_only" which removes rows of data flagged as having "Invalid" characteristic-media-result unit combinations. When clean = "nonstandardized_only", the function removes rows of data flagged as having "NonStandardized" characteristic-media-result unit combinations. When clean = "both", the function removes rows of data flagged as either "Invalid" or "NonStandardized". And when clean = "none", the function does not remove any "Invalid" or "NonStandardized" rows of data.
- flaggedonly
Boolean argument; filters dataframe to show only "Invalid" characteristic-media-result unit combinations when flaggedonly = TRUE. Default is flaggedonly = FALSE.
Value
This function adds the TADA.ResultUnit.Flag to a TADA dataframe. This column flags each CharacteristicName, ActivityMediaName, and ResultMeasure/MeasureUnitCode combination in your dataframe as either "NonStandardized", "Invalid", "Valid", or "Not Reviewed". When clean = "none" and flaggedonly = TRUE, the dataframe is filtered to show only the "Invalid" and "NonStandardized" data; the column TADA.ResultUnit.Flag is still appended. When clean = "invalid_only" and flaggedonly = FALSE, "Invalid" rows are removed from the dataframe, but "NonStandardized" rows are retained. When clean = "nonstandardized_only" and flaggedonly = FALSE, "NonStandardized" rows are removed, but "Invalid" rows are retained. The default is clean = "invalid_only" and flaggedonly = FALSE.
Details
The “Not Reviewed” value within "TADA.ResultAboveUpperThreshold.Flag" means that the EPA WQX team has not yet reviewed the combinations (see https://cdx.epa.gov/wqx/download/DomainValues/QAQCCharacteristicValidation.CSV). The WQX team plans to review and update these new combinations quarterly.
Examples
# Load example dataset:
data(Data_Nutrients_UT)
# Remove data with invalid characteristic-media-result unit combinations from dataframe,
# but retain "NonStandardized" combinations flagged in new column 'TADA.ResultUnit.Flag':
InvalidUnit_clean <- TADA_FlagResultUnit(Data_Nutrients_UT)
# Remove data with "NonStandardized" characteristic-media-result unit combinations
# from dataframe but retain invalid combinations flagged in new column 'TADA.ResultUnit.Flag:
NonstandardUnit_clean <- TADA_FlagResultUnit(Data_Nutrients_UT, clean = "nonstandardized_only")
# Remove both invalid and "NonStandardized" characteristic-media-result unit combinations
# from dataframe:
ResultUnit_clean <- TADA_FlagResultUnit(Data_Nutrients_UT, clean = "both")
# Flag, but do not remove, data with invalid or "NonStandardized" characteristic-media-result unit
# combinations in new column titled "TADA.ResultUnit.Flag":
InvalidUnit_flags <- TADA_FlagResultUnit(Data_Nutrients_UT, clean = "none")
#> [1] "Rows with invalid result value units have been flagged but retained. Review these rows before proceeding and/or set clean = 'invalid_only' or 'both'."
# Show only invalid characteristic-media-result unit combinations:
InvalidUnit_flaggedonly <- TADA_FlagResultUnit(Data_Nutrients_UT, clean = "nonstandardized_only", flaggedonly = TRUE)
#> [1] "This dataframe is empty because either we did not find any invalid/NonStandardized characteristic-media-result unit combinations or they were all filtered out"
# Show only "NonStandardized" characteristic-media-result unit combinations:
NonstandardUnit_flaggedonly <- TADA_FlagResultUnit(Data_Nutrients_UT, clean = "invalid_only", flaggedonly = TRUE)
#> [1] "This dataframe is empty because either we did not find any invalid/NonStandardized characteristic-media-result unit combinations or they were all filtered out"