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)
You could also try: (df1 is the dataset)
df1
indx <- which(!is.na(df1), arr.ind=TRUE) df1[cbind(1:nrow(df1),tapply(indx[,2], indx[,1], FUN=max))] #[1] "Cucumber" "Apple" "Lime" "Honey"