My question has strong similarities with this one and this other one, but my dataset is a little bit different and I can\'t seem to make those solutions work. Please excuse me i
You can also try:
colnames(df)[2:5][max.col(!is.na(df[,2:5]))]
#[1] "conditionA" "conditionB" "conditionC" "conditionD" "conditionA"
The above works if one and only one column has a value other than NA
for each row. If the values of a row can be all NA
s, then you can try:
mat<-!is.na(df[,2:5])
colnames(df)[2:5][max.col(mat)*(NA^!rowSums(mat))]