1
$\begingroup$

(This is my first time posting code so I may have done it wrong.)

I have a list of data that was collected and reported in 5 year increments for a couple of decades; then the gap was three years until more recently it was annual. I wish to fill the five- and three-year gaps with the intervening average values. List Interpolation gives me a function but it seems there should be a simpler way. Here is the list

{{"Australia", "AUS", 1990, 13.131}, {"Australia", "AUS", 1995, 
  16.871}, {"Australia", "AUS", 2000, 18.242}, {"Australia", "AUS", 
  2005, 16.681}, {"Australia", "AUS", 2010, 16.706}, {"Australia", 
  "AUS", 2013, 18.109}, {"Australia", "AUS", 2014, 
  18.697}, {"Australia", "AUS", 2015, 18.794}, {"Australia", "AUS", 
  2016, 19.146}}

The code below works for the five year gap (illustrated is the 1995-2000 gap) and I modify it for the three year, then glue them all together with Join. Very clunky. I am sure there is a more elegant way and appreciate any suggestions

soc6 = Differences[soc5[[2 ;; 3]]]/5

({0.2742})

soclist2 = 
 Drop[FoldList[Plus, 
   soc5[[2]], {soc6[[1]], soc6[[1]], soc6[[1]], soc6[[1]], 
    soc6[[1]]}], 1]

({17.1452, 17.4194, 17.6936, 17.9678, 18.242})

$\endgroup$

1 Answer 1

1
$\begingroup$

Using TimeSeriesResample:

data = {{"Australia", "AUS", 1990, 13.131},
        {"Australia", "AUS", 1995, 16.871},
        {"Australia", "AUS", 2000, 18.242},
        {"Australia", "AUS", 2005, 16.681},
        {"Australia", "AUS", 2010, 16.706},
        {"Australia", "AUS", 2013, 18.109},
        {"Australia", "AUS", 2014, 18.697},
        {"Australia", "AUS", 2015, 18.794},
        {"Australia", "AUS", 2016, 19.146}};

Join[data[[1, ;; 2]], #] & /@ 
 TimeSeriesResample[TimeSeries[data[[All, 3 ;;]]]]["Path"]

Plotting without the "Australia, "AUS" bit:

ListLinePlot[
 TimeSeriesResample[TimeSeries[data[[All, 3 ;;]]], 
   ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}]["Path"]
 , Mesh -> All, PlotTheme -> "Detailed"]

resampled plot

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.