Given data that looks like:
library(data.table) DT <- data.table(x=rep(1:5, 2))
I would like to split this data into 5 boolean columns t
library(data.table) DT <- data.table(x=rep(1:5, 2)) # add column with id DT[, id := seq.int(nrow(DT))] # cast long table into wide DT.wide <- dcast(DT, id ~ x, value.var = "x", fill = 0, fun = function(x) 1)