title: Creating Column Based on Date Order, Rotating Dataset R
body: <p>I have a dataset that looks like the following:</p>
  
  <pre><code>ID= c("A","A","A","A","B","B","C","C","C")
  Date= as.Date(c("2017-09-24", "2017-09-26", "2017-09-23", "2017-09-30","2017-09-12", "2017-09-15", "2017-09-01", "2017-09-30", "2017-09-25"))
  Data= c(10,5,15,20,8,9,5,6,2)
  df= data.frame(ID, Date, Data)
  d
    ID       Date Data
  1  A 2017-09-24   10
  2  A 2017-09-26    5
  3  A 2017-09-23   15
  4  A 2017-09-30   20
  5  B 2017-09-12    8
  6  B 2017-09-15    9
  7  C 2017-09-01    5
  8  C 2017-09-30    6
  9  C 2017-09-25    2
  </code></pre>
  
  <p>I am attempting to add an additional column that is in descending order by the  Date column per ID in Descending Order, such that I have the following output:</p>
  
  <pre><code>   ID Order      Date   Data
  1  A     3 2017-09-24   10
  2  A     2 2017-09-26    5
  3  A     4 2017-09-23   15
  4  A     1 2017-09-30   20
  5  B     2 2017-09-12    8
  6  B     1 2017-09-15    9
  7  C     3 2017-09-01    5
  8  C     1 2017-09-30    6
  9  C     2 2017-09-25    2
  </code></pre>
  
  <p>I have used striptime() and order() to attempt to get an Order column, but I am unsure of how to loop it per ID. </p>
  
  <p>I am then attempting to rotate the dataframe so that each Order has its own column, and the observations are the data contained in the Data column :</p>
  
  <pre><code>  ID Order4 Order3 Order2 Order1
  1  A     15     10      5     20
  2  B                    8      9
  3  C             5      2      6
  </code></pre>
  
  <p>I have tried to use tidyr's spread() to accomplish the dataset rotation, but it does not behave well since there is columns of differing length. </p>
  
  <p>Thank you a lot</p>