Here is an approach that will avoid usingapply
on a data.table
(which coerces to matrix internally)
dt[, na.cols := gsub('(^,+)|(,+$)','',do.call(paste, c(lapply(seq_along(.SD), function(x) ifelse(is.na(.SD[[x]]),names(.SD)[x],'')), sep=',')))]
# a b c na.cols
# 1: 1 1 NA c
# 2: 2 2 2
# 3: 3 NA NA b,c
# 4: NA NA 4 a,b