I have a table with binary values that I want to summarize into one column. Here is an example:
df <- data.frame("User" = c("User A", "User B", "User C"), "quality 1" = c(0,0,1), "quality 2" = c(1,0,0), "quality 3" = c(0,1,0))
I'd like to run function that generates a dataframe like this:
summary <- data.frame("User" = c("User A", "User B", "User C"), "qualityNumber" = c("quality.2", "quality.3", "quality.1") )
For each row, the new variable ("qualityNumber") is assigned the column name from the original df that contains 1.
I have tried using dplyr and which(), but I can't figure it out.
My attempt:
summary = df %>%
mutate(
qualityNumber=
colnames(df[which(2:4 == 1)])
)