Creating multiple dummies from an existing data frame or data table
问题 I am looking for a quick extension to the following solution posted here. In it Frank shows that for an example data table test <- data.table("index"=rep(letters[1:10],100),"var1"=rnorm(1000,0,1)) You can quickly make dummies by using the following code inds <- unique(test$index) ; test[,(inds):=lapply(inds,function(x)index==x)] Now I want to extend this solution for a data.table that has multiple rows of indices, e.g. new <- data.table("id" = rep(c("Jan","James","Dirk","Harry","Cindy",