title: Create New Column That Takes Column Name Based on Value
body: <p>I have a table with binary values that I want to summarize into one column. Here is an example:</p>
  <pre><code>df &lt;- data.frame(&quot;User&quot; = c(&quot;User A&quot;, &quot;User B&quot;, &quot;User C&quot;), &quot;quality 1&quot; = c(0,0,1), &quot;quality 2&quot; = c(1,0,0), &quot;quality 3&quot; = c(0,1,0))
  </code></pre>
  <p>I'd like to run function that generates a dataframe like this:</p>
  <pre><code>summary &lt;- data.frame(&quot;User&quot; = c(&quot;User A&quot;, &quot;User B&quot;, &quot;User C&quot;), &quot;qualityNumber&quot; = c(&quot;quality.2&quot;, &quot;quality.3&quot;, &quot;quality.1&quot;) )
  </code></pre>
  <p>For each row, the new variable (&quot;qualityNumber&quot;) is assigned the column name from the original df that contains 1.</p>
  <p>I have tried using dplyr and which(), but I can't figure it out.</p>
  <p>My attempt:</p>
  <pre><code>summary = df %&gt;%
  mutate(
      qualityNumber= 
        colnames(df[which(2:4 == 1)])
      )
  </code></pre>