title: Subset dataframe using a loop
body: <p>I have a data frame that looks like this:</p>
  <pre><code>index   ID   date              Amount
  2       1001 2010-06-08         0
  21      1001 2010-10-08        10
  6       1002 2010-08-16        30
  5       1002 2010-11-25        20
  9       1003 2010-01-01         0
  8       1003 2011-03-06        10
  12      1004 2012-03-12        10
  11      1004 2012-06-21        10
  15      1005 2010-01-01        30
  13      1005 2010-04-06        20
  </code></pre>
  <p>I want to subset this data so that I have new data frames, one for each ID like this</p>
  <pre><code>index   ID   date              Amount
  2       1001 2010-06-08         0
  21      1001 2010-10-08        10
  </code></pre>
  <p>And</p>
  <pre><code>6       1002 2010-08-16        30
  5       1002 2010-11-25        20
  </code></pre>
  <p>And so on.</p>
  <p>I don't need to save the new data frames, but use it to perform some basic calculations. Also I want to do this on my entire table consisting of more than 10000 IDs and hence the need for a loop. I tried this</p>
  <pre><code>    temp &lt;- data.frame(Numb=c(),Dt=c(),Amt=c())
  for (i in seq_along(stNew$ID)){
     temp[i,] &lt;- subset(stNew, stNew[i,]==stNew$ID[i])
  }
  </code></pre>
  <p>But that didn't work. Any suggestions?</p>