I am still a beginner R user. To simplify the problem I have, basically, I have a data frame very similar to the code indicated below. I have three separate variables with 1's if the variable is true, and NA if it is false. These variables should really all be in one column. How do I do that? Each color is a separate column, but I want there to be one color column with different colors as the values in the column. I tried using if else, else if statements, but was getting error messages that I could not understand.
Thank you so much for any assistance you are able to give!
# This is basiablly what my data is like.
df <- data.frame(ID = c(1, 2, 3, 4, 5),
Blue = c(1, NA, NA, NA, 1),
Green = c(NA, NA, 1, NA, NA),
Red = c(NA, 1, NA, 1, NA))
# I want to put the above data into this new column.
df$color <- NA
#This is a simplified example of what I tried, but got errors that I can't figure out
if (df$Blue == 1){
df$color == "Blue"
} else if (df$Green == 1){
df$color == "Green"
} else {
df$color == "Red"
}