Take this sample data:
data.frame(a_1=c(\"Apple\",\"Grapes\",\"Melon\",\"Peach\"),a_2=c(\"Nuts\",\"Kiwi\",\"Lime\",\"Honey\"),a_3=c(\"Plum\",\"Apple\",NA,NA)
Another alternative that might be pretty fast:
DF[cbind(seq_len(nrow(DF)), max.col(!is.na(DF), "last"))]
#[1] "Cucumber" "Apple" "Lime" "Honey"
Where "DF":
DF = structure(list(a_1 = structure(1:4, .Label = c("Apple", "Grapes",
"Melon", "Peach"), class = "factor"), a_2 = structure(c(4L, 2L,
3L, 1L), .Label = c("Honey", "Kiwi", "Lime", "Nuts"), class = "factor"),
a_3 = structure(c(2L, 1L, NA, NA), .Label = c("Apple", "Plum"
), class = "factor"), a_4 = structure(c(1L, NA, NA, NA), .Label = "Cucumber", class = "factor")), .Names = c("a_1",
"a_2", "a_3", "a_4"), row.names = c(NA, -4L), class = "data.frame")