I was trying to find a quick way to do this yesterday via tidyverse but I wasn't able to do so. I want to essentially create dummy columns but on the input of three columns.
You will see that we have a data frame below. As an example with row 12 we have the values 1,12,11 respective to a,b,c. Thus, the new column "1" should have a 1 there and all other columns should contain 0 until we get to 11 and 12 for that row which also contain a 1 for their respective columns. Just to add a second example, row 1 which is 14,6,10 should have 0's for all values in the new columns on their first row expect for 6,10,14 which should have a 1.
I sort of expect that a lot of mutates will have to happen to create the range but not sure how to write the logical expression concisely to be as little as possible code.
set.seed(333)
df <- data.frame(a = sample(1:17,15),
b = sample(1:17,15),
c = sample(1:17,15))
I presume you want the 'binary' form of one-hot encoding i.e. the column should contain 1 even if the same number is repeated more than once. If instead you want to represent how many times it occurred, simply change values_fn to list(count = sum).