Transforming one-hot encoded variable to one column
I have age columns like so that are dummy encoded. How can transform these columns to one column using dplyr?
Input:
age_0-10 age_11-20 age_21-30 age_31-40 age_41-50 age_51-60 gender
1 0 1 0 0 0 0 0
2 0 0 1 0 0 0 1
3 0 0 0 1 0 0 0
4 0 1 0 0 0 0 1
5 0 0 0 0 0 1 1
Expected Output:
age gender
1 11-20 0
2 21-30 1
3 31-40 0
4 11-20 1
5 51-60 1
from Recent Questions - Stack Overflow https://ift.tt/3EmXY41
https://ift.tt/eA8V8J
Comments
Post a Comment