Deduplicates AST records in two sequential steps:
Exact-duplicate removal: drops rows that are fully identical across all five key columns (patient + organism + antibiotic + date + value). These are true redundant records with no ambiguity.
Conflict resolution: handles the remaining cases where the same patient + organism + antibiotic + date group has different values.
Arguments
- data
Data frame with AST data in long format.
- mode
Character.
"detect"(flag only) or"remove"(flag then resolve). Default"detect".- strategy
Character. Resolution strategy used only when
mode = "remove". One of"resistant_wins"(default),"susceptible_wins", or"first".- patient_col
Character. Patient ID column. Default
"patient_id".- organism_col
Character. Organism column. Default
"organism_normalized".- antibiotic_col
Character. Antibiotic column. Default
"antibiotic_normalized".- date_col
Character. Culture date column. Default
"culture_date".- ast_col
Character. Harmonized AST value column. Default
"ast_value_harmonized".
Value
mode = "detect": original data withis_ast_duplicatelogical column added.mode = "remove": data with conflicts resolved (one row per key) and no flag column.
Details
"detect"After exact-dedup, flags conflicting rows with
is_ast_duplicate = TRUEand prints a QC summary. Returns the data with the flag column so you can inspect before deciding how to resolve."remove"Runs both steps: removes exact duplicates, then applies
strategyto keep one row per key combination for any remaining conflicts.