title: Merge rows with condition and limit in a dataframe
body: <p>I have the following dummy dataset of 1000 observations:</p>
  
  <pre><code>obs &lt;- 1000
  
  df &lt;- data.frame(
    a=c(1,0,0,0,0,1,0,0,0,0),
    b=c(0,1,0,0,0,0,1,0,0,0),
    c=c(0,0,1,0,0,0,0,1,0,0),
    d=c(0,0,0,1,0,0,0,0,1,0),
    e=c(0,0,0,0,1,0,0,0,0,1),
    f=c(10,2,4,5,2,2,1,2,1,4),
    g=sample(c("yes", "no"), obs, replace = TRUE),
    h=sample(letters[1:15], obs, replace = TRUE),
    i=sample(c("VF","FD", "VD"), obs, replace = TRUE),
    j=sample(1:10, obs, replace = TRUE)
  )
  </code></pre>
  
  <p>One key feature of this dataset is that the variables <code>a</code> to <code>e</code>'s values are only one <code>1</code> and the rest are <code>0</code>. We are sure the only one of these five columns have a <code>1</code> as value.</p>
  
  <p>I found <a href="https://stackoverflow.com/a/5391697/1685185">a way to extract these rows given a condition</a> (with a <code>1</code>) and assign to their respective variables:</p>
  
  <pre><code>df.a &lt;- df[df[,"a"] == 1,,drop=FALSE]
  df.b &lt;- df[df[,"b"] == 1,,drop=FALSE]
  df.c &lt;- df[df[,"c"] == 1,,drop=FALSE]
  df.d &lt;- df[df[,"d"] == 1,,drop=FALSE]
  df.e &lt;- df[df[,"e"] == 1,,drop=FALSE]
  </code></pre>
  
  <p>My dilemma now is to limit the rows saved into <code>df.a</code> to <code>df.e</code> and to merge them afterwards.</p>