title: Weighted Average by Year in ragged data frame in R
body: <p>I have a data frame with eight variables. I would like to calculate the average mean of annual weighted average percent loss. However, not all variables exist for each year in my dataset. What would be the simplest method to do so? Included below is a sample dataset and final desired output.</p>
  
  <p>Thank you!</p>
  
  <p>sample dataset</p>
  
  <pre><code>Fruit.Type  Year    Primary.Wgt Primary.Loss.PCT    Retail.Wgt  Retail.Loss.PCT Cons.Wgt    Cons.Loss.PCT
  Oranges.F   1970    16.16   3.0 15.68   11.6    13.86   36.0
  Oranges.F   1971    15.73   3.0 15.26   11.6    13.49   36.0
  Oranges.F   1972    14.47   3.0 14.04   11.6    12.41   36.0
  Oranges.F   1973    14.43   3.0 14.00   11.6    12.38   36.0
  Tangerines.F    1971    2.34    5.0 2.22    20.4    1.80    52.0
  Tangerines.F    1972    2.06    5.0 1.96    20.4    1.60    52.0
  Tangerines.F    1973    2.07    5.0 1.97    20.4    1.60    52.0
  Grapefruit.F    1970    8.22    3.0 7.97    12.8    6.90    20.0
  Grapefruit.F    1971    8.55    3.0 8.29    12.8    7.20    20.0
  Grapefruit.F    1972    8.56    3.0 8.31    12.8    7.20    20.0
  Grapefruit.F    1973    8.57    3.0 8.31    12.8    7.20    20.0
  </code></pre>
  
  <p>desired output (calc'd in excel)
  Output (weighted average percent loss)          </p>
  
  <pre><code>Year    Primary.Loss.PCT    Retail.Loss.PCT Cons.Loss.PCT
  1970    3.00    11.82   11.98
  1971    3.00    14.95   32.16
  1972    3.16    14.66   31.78
  1973    3.17    14.68   31.77
  
  Mean    3.08    14.03   26.92
  Standard Error  0.048   0.737   4.980
  </code></pre>