I have a data.table of factor columns, and I want to pull out the label of the last non-missing value in each row. It\'s kindof a typical max.col situation, bu
max.col
Here is a one liner base R approach:
base R
sapply(split(dat, seq(nrow(dat))), function(x) tail(x[!is.na(x)],1)) # 1 2 3 4 5 6 7 8 #"u" "q" "w" "h" "r" "t" "e" "t"