Original df (clinical chemistry)
Subject Code Test Value Units Flag
1 NA NA 147 mmol/L
2 NA/K NA/K 10.5 RATIO
3 K K 4.7 mmol/L
4 CK CK 235 UL
...
Ideal df after cleaning
Subject Code Test Value Units Flag
1 NA Sodium 147 mmol/L NA
2 NA/K Sodium Potassium 10.5 RATIO NA
3 K Potassium 4.7 mmol/L NA
4 CK Creatine Kinase 235 UL NA
...
What I have tried
df <- read.csv(file="clinchemistry.csv", header = TRUE, sep=",", stringsAsFactors = FALSE)
df$df[df8$Test == "NA"] <- "Sodium"
df$df[df8$Code == "NA"] <- "Sodium"
and
df[is.na(lb$Code)]<-"Sodium"
lb[is.na(lb$Code)]<-"Sodium"
RESULTS:
All the sodium values disappear or get an error:
Error in
[<-.data.frame
(*tmp*
, is.na(lb$Tesst), value = "Sodium") : duplicate subscripts for columns
WOULD SOMEONE GUIDE MY THINKING?