fix_sboe_id_missing <- function(sboe_id, report_id) { idx_missing <- which(sboe_id == "No Id") if (!length(idx_missing)) { return(sboe_id) } # can't fix `sboe_id` if we don't have a `report_id` idx_has_report_id <- which(!is.na(report_id)) if (!length(idx_has_report_id)) { return(sboe_id) } idx_missing <- union(idx_missing, idx_has_report_id) sboe_id[idx_missing] <- paste0("NOID-", report_id[idx_missing]) sboe_id }