i have a data table like this one:
a <- data.table::data.table(A = seq(1:5), B = c("V1","V2","V1","V2","V3"))
and i need a result with new columns V1, V2, V3 (there are some more possible values then 3) with 0 or 1 (true or false) depending on the value in B. So the result should look like this one:
A B V1 V2 V3
1: 1 V1 1 0 0
2: 2 V2 0 1 0
3: 3 V1 1 0 0
4: 4 V2 0 1 0
5: 5 V3 0 0 1
I have tried pivot_wider with no success. I have tried spread with diag function with no success.
Does anyone has a solution. Thank you very much.
." So i tried the solution with fastDummies and it worked also for my real Data. Thanks a lot to you guys.