mardi 15 juin 2021

How do I create a binary column based off characters in another column in R?

ROW   ID       SEX               RACE               
2  REC1000023   F                1.Black
7  REC1000032   M                6.White
8  REC1000066   M                4.Asian
9  REC1000078   M                6.White
10 REC1000099   M                5.Multiracial 

I would like to create a binary variable "Black" and have it be 0 or 1 depending on the value in the "RACE" column. I would also like a "White" column and an "Other" column. Like so:

ROW   ID       SEX               RACE           Black   White  Other        
2  REC1000023   F                1.Black         1      0      0
7  REC1000032   M                6.White         0      1      0
8  REC1000066   M                4.Asian         0      0      1
9  REC1000078   M                6.White         0      1      0
10 REC1000099   M                5.Multiracial   0      0      1

Aucun commentaire:

Enregistrer un commentaire