title: How to relevel a factor in R with 100 levels in R?
body: <p>I have a factor variable that has 100 levels with 0s and 1s. For example: 00000001, 01000000, 11000000, 00010001. Each level has 8 digits with 0 and 1s. What I want to do is to reorder the levels in a way that the sum of 1s is from smallest to largest. For example, I want 10000000, 01000000, 00100000, and other levels that only contains one 1. Followed by levels contain two 1s, and up to levels contain eight 1s. Is that any way that I can do that automatically instead of doing this manually?</p>
  
  <pre><code>df[,1] &lt;- factor(df[,1], levels=c("000", "001","100", "010","101","110","011","111"......))
  </code></pre>