I have a table full of binary variables that I would like to condense down to categorical variables.
Very simplistically, I have is a data frame like this:
data <- data.frame(id=c(1,2,3,4,5,6,7,8,9), red=c("1","0","0","0","1","0","0","0","0"),blue=c("0","1","1","1","0","1","1","1","0"),yellow=c("0","0","0","0","0","0","0","0","1"))
data
id red blue yellow
1 1 1 0 0
2 2 0 1 0
3 3 0 1 0
4 4 0 1 0
5 5 1 0 0
6 6 0 1 0
7 7 0 1 0
8 8 0 1 0
9 9 0 0 1
And what I would like to get back would be:
id color
1 1 red
2 2 blue
3 3 blue
4 4 blue
5 5 red
6 6 blue
7 7 blue
8 8 blue
9 9 yellow
I hope there's a really simple answer for this.