title: R transpose table dynamically for last X weeks
body: <p>I am new in R. I want to achieve the following.
  I have a table as below.</p>
  
  <pre><code>rowcounter  ProductNumber   YearNumber  WeekNumber  OrderedQuantity
  1   735001E083155   2016    2   10
  2   735001E083155   2016    3   20
  3   735001E083155   2016    3   10
  4   735001E083155   2016    4   60
  5   735001E083155   2016    4   50
  6   735001E083155   2016    5   20
  </code></pre>
  
  <p>I want to transpose this table so that I can get the last X number of weeks as columns with the proper OrderQuantities for Products. So an example would be;</p>
  
  <pre><code>rowcounter  ProductNumber   YearNumber  LastWeek Before2weeks Before3weeks 
  </code></pre>
  
  <p>and so on...</p>
  
  <p>the Ordered quantity should come under Lastweek, Before2weeks and so on... 
  I am planning to toggle the X something around 6 to 12.</p>
  
  <p>Appreciate your responses on how to make this as dynamic as possible.</p>