title: Efficiently removing missing values from the start and end of multiple time series in 1 data frame
body: <p>Using R, I'm trying to trim NA values from the start and end of a data frame that contains multiple time series. I have achieved my goal using a for loop and the zoo package, but as expected it is extremely inefficient on large data frames.</p>
  
  <p>My data frame look like this and contains 3 columns with each time series identified by it's unique id. In this case AAA, B and CCC.</p>
  
  <pre><code>id   date          value
  AAA  2010/01/01    NA
  AAA  2010/02/01    34
  AAA  2010/03/01    35
  AAA  2010/04/01    30
  AAA  2010/05/01    NA
  AAA  2010/06/01    28
  B    2010/01/01    NA
  B    2010/02/01    0
  B    2010/03/01    1
  B    2010/04/01    2
  B    2010/05/01    3
  B    2010/06/01    NA
  B    2010/07/01    NA
  B    2010/07/01    NA
  CCC  2010/01/01    0
  CCC  2010/02/01    400
  CCC  2010/03/01    300
  CCC  2010/04/01    200
  CCC  2010/05/01    NA
  </code></pre>
  
  <p>I would like to know, how can I efficiently remove the NA values from the start and end of each time series, in this case AAA, B and CCC. So it should look like this.</p>
  
  <pre><code>id   date          value
  AAA  2010/02/01    34
  AAA  2010/03/01    35
  AAA  2010/04/01    30
  AAA  2010/05/01    NA
  AAA  2010/06/01    28
  B    2010/02/01    0
  B    2010/03/01    1
  B    2010/04/01    2
  B    2010/05/01    3
  CCC  2010/01/01    0
  CCC  2010/02/01    400
  CCC  2010/03/01    300
  CCC  2010/04/01    200
  </code></pre>