title: Class Assign Based on Column Values
body: <p>I have dataset like the following:</p>
  
  <pre><code>a &lt;- structure(list(ID = c("a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"), 
                      E = c(1, 0, 0, 0,4, 4, 3, 0,1), 
                      W = c(0, 3, 2, 0, 3, 3, 3, 4,1), 
                      N = c(1, 0, 2, 0, 3, 4, 3, 7,1), 
                      S=c(0, 0, 0, 2, 1, 1, 3, 0,1)), 
                 .Names = c("ID", "E", "W", "N", "S"), row.names = c(NA, -9L), class = "data.frame")
  a
    ID E W N S
  1 a1 1 0 1 0
  2 a2 0 3 0 0
  3 a3 0 2 2 0
  4 a4 0 0 0 2
  5 a5 4 3 3 1
  6 a6 4 3 4 1
  7 a7 3 3 3 3
  8 a8 0 4 7 0
  9 a9 1 1 1 1
  </code></pre>
  
  <p>I like to create a <code>class</code> column, that will show the <code>column name</code> based on the maximum number for each row. For example, the second row with ID <code>a2</code> has a <em>maximum value</em> 3 for <code>W</code> column. The class will be <code>W</code> and max will be 3. When a tie happens <strong>in the maximum values</strong>, it will include all the tied column names. For example, for row 1 (<code>ID=a1</code>), both column <code>E</code> and column <code>N</code> has the same <strong>maximum value</strong>, so the class will be defined as <code>E-N</code>, and max will be 1.</p>
  
  <p>I have started with <code>melt</code> function:</p>
  
  <pre><code>library(reshape2)
  a1= melt(a, id=c("ID"))
  head(a1)
    ID variable value
  1 a1        E     1
  2 a2        E     0
  3 a3        E     0
  4 a4        E     0
  5 a5        E     4
  6 a6        E     4
  </code></pre>
  
  <p>The final output will be:</p>
  
  <pre><code>  ID   Class Max
  1 a1     E-N   1
  2 a2       W   3
  3 a3     W-N   2
  4 a4       S   2
  5 a5       E   4
  6 a6     E-N   4
  7 a7 E-W-N-S   3
  8 a8       N   7
  9 a9 E-W-N-S   1
  </code></pre>