title: Merging rows with the same ID variable
body: <p>I have a dataframe in R with 2186 obs of 38 vars. Rows have an ID variable referring to unique experiments and using </p>
  
  <pre><code>length(unique(df$ID))==nrow(df)
  
  n_occur&lt;-data.frame(table(df$ID))
  </code></pre>
  
  <p>I know 327 of my rows have repeated IDs with some IDs repeated more than once. I am trying to merge rows with the same ID as these aren't duplicates but just second, third etc. observations within a given experiment. </p>
  
  <p>So for example if I had</p>
  
  <pre><code>x y ID
  1 2 a
  1 3 b
  2 4 c
  1 3 d
  1 4 a
  3 2 b
  2 3 a
  </code></pre>
  
  <p>I would like to end up with </p>
  
  <pre><code>x y ID x2 y2 ID2 x3 y3 ID3
  1 2 a  1  4  a   2  3  a
  1 3 b  3  2  b  na na na
  2 4 c  na na na na na na
  1 3 d  na na na na na na
  </code></pre>
  
  <p>I've seen similar questions for SQL and php but this hasn't helped me with my attempts in R. Any help would be gratefully appreciated. </p>