I have a dataset in a csv file that looks like this:
X Colour Orange Red White Violet Black Yellow Blue
1 1 Orange, Red NA NA NA NA NA NA NA
2 2 Red NA NA NA NA NA NA NA
3 3 White, Black NA NA NA NA NA NA NA
4 4 Yellow NA NA NA NA NA NA NA
5 5 Blue, Orange, Violet NA NA NA NA NA NA NA
I am trying to add 0 and 1 for each combination of column columns. Expected Result:
Colour Orange Red White Violet Black Yellow Blue
1 Orange,Red 1 1 0 0 0 0 0
2 Red 0 1 0 0 0 0 0
3 White,Black 0 0 1 0 1 0 0
4 Yellow 0 0 0 0 0 1 0
5 Blue,Orange, 1 0 0 1 0 0 1
Violet
How to achieve this in R?
source
share