В base R
мы можем использовать max.col
Grade <- max.col(df1 != "nil") * NA^!rowSums(df1 != "nil")
Complications <- df1[cbind(seq_len(nrow(df1)), Grade)]
setNames(replace(Grade, is.na(Grade), "nil"),
replace(Complications, is.na(Complications), "nil"))
# fever other nil trans
# "3" "3" "nil" "1"
данные
df1 <- structure(list(G1 = c("nil", "nil", "nil", "trans"), G2 = c("nil",
"nil", "nil", "nil"), G3 = c("fever", "other", "nil", "nil")),
class = "data.frame", row.names = c("1",
"2", "3", "4"))