'How to split the components of a column (characters) into several numeric columns (1 and 0) in R?
I have a database in this form: Num_customer Product label 1020 TCAR Active agent 1096 Agent-Family card 1067 Senior 20 CSC units 1034 TCAR Active agent 1011 TCAR Active agent 1022 Bike Park 1020 Bike Park
And I want to separate the product label column into 6 columns (the column names will be the product types) and assign for each Num_customer , numbers 0 if the product does not match and 1 matches. What I want to get looks like this:
Num_customer TCAR Active agent Agent-Family card Senior 20 CSC units Bike Park 1020 1 0 0 1 1096 0 1 0 0 1067 0 0 1 0 1034 1 0 0 0 1011 1 0 0 0 1022 0 0 0 1
My data frame is large and there are 20 product types. I will be grateful if you can help me to solve this problem!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
