I have a roster of employees, and I need to know at what department they are in most often. It is trivial to tabulate employee ID against department name, but it is trickier
Here is an answer that works with data.table and is simpler. This assumes your data.table is named yourDF:
yourDF
j1 <- max.col(yourDF[, .(V1, V2, V3, V4)], "first") yourDF$newCol <- c("V1", "V2", "V3", "V4")[j1]
Replace ("V1", "V2", "V3", "V4") and (V1, V2, V3, V4) with your column names
("V1", "V2", "V3", "V4")
(V1, V2, V3, V4)