dummy variables to single categorical variable (factor) in R
问题 I have a set of variables coded as binomial. Pre VALUE_1 VALUE_2 VALUE_3 VALUE_4 VALUE_5 VALUE_6 VALUE_7 VALUE_8 1 1 0 0 0 0 0 1 0 0 2 1 0 0 0 0 1 0 0 0 3 1 0 0 0 0 1 0 0 0 4 1 0 0 0 0 1 0 0 0 I would like to merge the variables (VALUE_1, VALUE_2...VALUE_8) into one single ordered factor, while conserving the column (Pre) as is, duch that the data would look like this: Pre VALUE 1 1 VALUE_6 2 1 VALUE_5 3 1 VALUE_5 Or even better: Pre VALUE 1 1 6 2 1 5 3 1 5 I am aware that this exists: