title: Collapse data by ID in data frame in R
body: <p>I am try to collapse data by ID and Gender.
  I have the data frame:</p>
  
  <pre><code>ID &lt;- c(1,1,1,1,2,2,2,3,3,3,4,4,4)
  Gender &lt;- c("M","M","M","M","F","F",'F',"F","F","F", "M", "M", "M")
  Test1 &lt;- c("70", "NA", "NA", "NA", "NA", "85", "NA", "NA", "90", "NA", "NA", "NA", "90")
  Test2 &lt;- c("NA", "60", "NA", "NA", "NA", "NA", "82", "NA", "NA", "87", "NA", "88", "NA")
  
  df &lt;- data.frame(ID, Gender, Test1, Test2)
  
     ID Gender Test1 Test2
  1   1      M    70    NA
  2   1      M    NA    60
  3   1      M    NA    NA
  4   1      M    NA    NA
  5   2      F    NA    NA
  6   2      F    85    NA
  7   2      F    NA    82
  8   3      F    NA    NA
  9   3      F    90    NA
  10  3      F    NA    87
  11  4      M    NA    NA
  12  4      M    NA    88
  13  4      M    90    NA
  </code></pre>
  
  <p>I am hoping to get help on how to collapse the data across ID and Gender so I can have 1 row per ID. Which would look like this: </p>
  
  <pre><code>  id gender test1 test2
  1  1      M    70    60
  2  2      F    85    82
  3  3      F    90    87
  4  4      M    90    88
  </code></pre>
  
  <p>Any help would be greatly appreciated!
  Thanks!</p>