title: transposing data with macro
body: <p>I would like to transpose my data using a loop and not the typical transpose function so I don't have to merge the data with unused variables.  </p>
  
  <p>Data I have is the following:</p>
  
  <pre><code>df1 &lt;- data.frame(ID=c(1:4), Amount=c(100, 150, 75, 50), 
      Month=c("Jan", "Feb", "Mar", "Apr"))
  </code></pre>
  
  <p>Which gives the following results:</p>
  
  <pre><code>ID Amount Month
  1    100   Jan
  2    150   Feb
  3     75   Mar
  4     50   Apr
  </code></pre>
  
  <p>I would like the final results to be like this:</p>
  
  <pre><code>ID Amount Jan Feb Mar Apr
  1    100   1   0   0   0
  2    150   0   1   0   0
  3     75   0   0   1   0
  4     50   0   0   0   1
  </code></pre>
  
  <p>I would know how to do this in SAS but couldn't find a solution with R.  Your help is appreciated. </p>