Я пытаюсь создать новую переменную lab_conf
на основе соответствия любому условию для 2 других переменных diagnosis
и PC_R
.Вот код, который я использую:
mutate(lab_conf = ifelse( (diagnosis == "confirmed")|(PC_R == "pos"), "pos", "neg"))
Вывод, который я получаю, показывает NA, где он должен показывать «neg», поэтому я получаю только 2 значения;«pos» или «NA».Я хотел бы, чтобы значения для этой новой переменной были либо "pos", "neg", либо NA на основе указанных условий, где NA было бы, если это NA в обоих условиях.
Вот чтоЯ получаю с dput(head(x))
:
structure(list(diagnosis = structure(c(16L, 16L, 16L, 3L, 16L,
3L), .Label = c("*un-confirmed", "Cloted sample", "confirmed",
"Hemolysed sampl", "inadequate sample", "rej (sample leaking)",
"rej(Hemolyzed sample)", "rej(Hemolyzed)", "rej: sample Hemolyzed",
"rej: sample leaking", "rej: sample leaking + Hemolyzed", "rej: sample leaking+not convnient tube",
"repeat sample", "tf", "TF", "un-confirmed"), class = "factor"),
PC_R = structure(c(NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), .Label = c("clotted",
"hemolyzed", "neg", "not pos", "Not REQUIred", "OTHER", "pos",
"QNS", "rej", "repeat sample", "Sample broken", "tf", "TF"
), class = "factor"), lab_conf = c(NA, NA, NA, "pos", NA,
"pos")), .Names = c("diagnosis", "PC_R", "lab_conf"), row.names = c(NA,
6L), class = "data.frame")