Mutate with dynamic column names dplyr
Hi I have this dataset (It has many more columns)
media brand radio tv cinema
chr dbl dbl dbl dbl
radio 0 0 0 0
tv 0 0 0 0
cinema 0 0 0 0
tv 0 0 0 0
radio 0 0 0 0
tv 0 0 0 0
I want to obtain the following(Assign a 1 to each column based on the value of media column):
media brand radio tv cinema
chr dbl dbl dbl dbl
radio 0 1 0 0
tv 0 0 1 0
cinema 0 0 0 1
tv 0 0 1 0
radio 0 1 0 0
tv 0 0 1 0
Do you have any idea on how to do it?As I have many more columns, I'm trying to find a solution using dynamic variable assignment. Thanks
Topic dplyr preprocessing r machine-learning
Category Data Science