Taking a 3 year average across in a panel data set with NAs
问题 I have the following dataframe, called DF, Country Year Var1 Var2 USA 2010 5 3 USA 2011 6 5 USA 2012 NA 8 USA 2013 4 NA USA 2014 NA 6 USA 2015 6 9 CHN 2010 NA 5 CHN 2011 7 NA CHN 2012 6 NA CHN 2013 4 4 CHN 2014 NA 6 CHN 2015 NA 8 EGY 2010 3 NA EGY 2011 3 5 EGY 2012 3 6 EGY 2013 NA 8 EGY 2014 NA NA EGY 2015 NA 2 I want to take a 3 year average of the data. However, if there are only two years of available data within a particular three year interval, I want to ignore the NA and take a two year