I am new to the data.table. I just know how to replace value column by column. Is there any way to do it by 1 command? Here my sample code:
DT1 = data.table(A=sample(3, 10, TRUE),
B=sample(3, 10, TRUE),
C=sample(3, 10, TRUE))
DT1[,A:=ifelse(A>1,1,0),]
DT1[,B:=ifelse(B>1,1,0),]
DT1[,C:=ifelse(C>1,1,0),]
Ideally there is a way to merge the last 3 command into 1. Thanks in advance.
library(dplyr); DT1 <- mutate_each(DT1, funs(as.integer(. > 1L)))