library(tidyverse)
lab <- tribble(
~usubjid, ~hgb, ~glu, ~chol, ~alb, ~alt, ~ast, ~ldh, ~crp,
"101", 12.5, 110, "POS", 4.2, "NEG", 21, NA, NA,
"102", 13.0, 105, "NEG", 4.1, "NEG", 25, NA, NA,
"103", NA, NA, NA, NA, NA, NA, NA, NA,
"104", 14.1, 108, "POS", 4.5, "NEG", 20, NA, NA )
lab_clean <- lab %>%
select(where(~ any(!is.na(.) & . != "")))
- The dataset `lab` includes a mix of numeric and character results.
- Some columns (`ldh`, `crp`) are completely missing for all subjects.
- `where(~ any(!is.na(.) & . != ""))` keeps only columns with at least one non-missing or non-blank value.
- The resulting `lab_clean` retains only relevant lab tests.