title: Data manipulation with forecasting data
body: <p>I am trying to make forecasting for sales from two stores: Store 1 and Store 2. Like results from forecasting with forecasting package I got this two table.First table contain data about MAPE error separably by each model(column Value).Below you can see data and screen shot of data.</p>
  
  <pre><code>Table_1&lt;-structure(list(...1 = c("1", "2", "3", "4", "5", "6", "7", "8", 
                          "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", 
                          "20"), X1 = c("SNAIVE", "HW", "ETS", "ARIMA", "STL", "TBATS", 
                                        "NNETAR", "RWF", "TSLM", "FOURIER", "SNAIVE", "HW", "ETS", "ARIMA", 
                                        "STL", "TBATS", "NNETAR", "RWF", "TSLM", "FOURIER"), X2 = c("Store 1", 
                                                                                                    "Store 1", "Store 1", "Store 1", "Store 1", "Store 1", "Store 1", 
                                                                                                    "Store 1", "Store 1", "Store 1", "Store 2", "Store 2", "Store 2", 
                                                                                                    "Store 2", "Store 2", "Store 2", "Store 2", "Store 2", "Store 2", 
                                                                                                    "Store 2"), value = c(11.2819379803024, 4.90469397146697, 4.90469397146697, 
                                                                                                                          4.64808116952175, 4.92695563666538, 6.11286061911487, 7.66061575087076, 
                                                                                                                          8.95984865369006, 5.07614708345642, 4.57448859126253, 22.7760224588221, 
                                                                                                                          24.0502857269679, 18.9376978459644, 21.6693712888351, 21.6029490199174, 
                                                                                                                          24.692214948761, 26.2680955559159, 30.5302345480261, 22.2367412218357, 
                                                                                                                          22.6100823447494)), row.names = c(NA, -20L), class = c("tbl_df", 
                                                                                                                                                                                 "tbl", "data.frame"))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/DEmou.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DEmou.jpg" alt="enter image description here"></a></p>
  
  <p>With yellow color I already highlighted best three models (with lowest MAPE error) from forecasting for Store 1 and Store 2.For Store 1 are (ETS,ARIMA and Fourier) and for Store 2 (ETS,ARIMA and STL).</p>
  
  <p>Second table contain forecasted data by each month from all this models.Below you can see data and also screen shot of data.</p>
  
  <pre><code>   Table2&lt;-structure(list(Date = structure(c(1575158400, 1577836800, 1580515200, 
                                         1583020800, 1585699200, 1588291200, 1590969600, 1593561600, 1596240000, 
                                         1598918400, 1601510400, 1604188800, 1606780800, 1575158400, 1577836800, 
                                         1580515200, 1583020800, 1585699200, 1588291200, 1590969600, 1593561600, 
                                         1596240000, 1598918400, 1601510400, 1604188800, 1606780800, 1575158400, 
                                         1577836800, 1580515200, 1583020800, 1585699200, 1588291200, 1590969600, 
                                         1593561600, 1596240000, 1598918400, 1601510400, 1604188800, 1606780800, 
                                         1575158400, 1577836800, 1580515200, 1583020800, 1585699200, 1588291200, 
                                         1590969600, 1593561600, 1596240000, 1598918400, 1601510400, 1604188800, 
                                         1606780800, 1575158400, 1577836800, 1580515200, 1583020800, 1585699200, 
                                         1588291200, 1590969600, 1593561600, 1596240000, 1598918400, 1601510400, 
                                         1604188800, 1606780800, 1575158400, 1577836800, 1580515200, 1583020800, 
                                         1585699200, 1588291200, 1590969600, 1593561600, 1596240000, 1598918400, 
                                         1601510400, 1604188800, 1606780800, 1575158400, 1577836800, 1580515200, 
                                         1583020800, 1585699200, 1588291200, 1590969600, 1593561600, 1596240000, 
                                         1598918400, 1601510400, 1604188800, 1606780800, 1575158400, 1577836800, 
                                         1580515200, 1583020800, 1585699200, 1588291200, 1590969600, 1593561600, 
                                         1596240000, 1598918400, 1601510400, 1604188800, 1606780800, 1575158400, 
                                         1577836800, 1580515200, 1583020800, 1585699200, 1588291200, 1590969600, 
                                         1593561600, 1596240000, 1598918400, 1601510400, 1604188800, 1606780800, 
                                         1575158400, 1577836800, 1580515200, 1583020800, 1585699200, 1588291200, 
                                         1590969600, 1593561600, 1596240000, 1598918400, 1601510400, 1604188800, 
                                         1606780800), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
                      Forecasting_model = c("SNAIVE", "SNAIVE", "SNAIVE", "SNAIVE", 
                                            "SNAIVE", "SNAIVE", "SNAIVE", "SNAIVE", "SNAIVE", "SNAIVE", 
                                            "SNAIVE", "SNAIVE", "SNAIVE", "HW", "HW", "HW", "HW", "HW", 
                                            "HW", "HW", "HW", "HW", "HW", "HW", "HW", "HW", "ETS", "ETS", 
                                            "ETS", "ETS", "ETS", "ETS", "ETS", "ETS", "ETS", "ETS", "ETS", 
                                            "ETS", "ETS", "ARIMA", "ARIMA", "ARIMA", "ARIMA", "ARIMA", 
                                            "ARIMA", "ARIMA", "ARIMA", "ARIMA", "ARIMA", "ARIMA", "ARIMA", 
                                            "ARIMA", "STL", "STL", "STL", "STL", "STL", "STL", "STL", 
                                            "STL", "STL", "STL", "STL", "STL", "STL", "TBATS", "TBATS", 
                                            "TBATS", "TBATS", "TBATS", "TBATS", "TBATS", "TBATS", "TBATS", 
                                            "TBATS", "TBATS", "TBATS", "TBATS", "NNAR", "NNAR", "NNAR", 
                                            "NNAR", "NNAR", "NNAR", "NNAR", "NNAR", "NNAR", "NNAR", "NNAR", 
                                            "NNAR", "NNAR", "RWF", "RWF", "RWF", "RWF", "RWF", "RWF", 
                                            "RWF", "RWF", "RWF", "RWF", "RWF", "RWF", "RWF", "TSLM", 
                                            "TSLM", "TSLM", "TSLM", "TSLM", "TSLM", "TSLM", "TSLM", "TSLM", 
                                            "TSLM", "TSLM", "TSLM", "TSLM", "FOURIER", "FOURIER", "FOURIER", 
                                            "FOURIER", "FOURIER", "FOURIER", "FOURIER", "FOURIER", "FOURIER", 
                                            "FOURIER", "FOURIER", "FOURIER", "FOURIER"), `Store 1` = c(8083, 
                                                                                                       1171, 1328, 1281, 1281, 1118, 1107, 1611, 1116, 1133, 1618, 
                                                                                                       1261, 8083, 8312, 1336, 1261, 1673, 1667, 1223, 1603, 1621, 
                                                                                                       1211, 1633, 1637, 1672, 8138, 8312, 1336, 1261, 1673, 1667, 
                                                                                                       1223, 1603, 1621, 1211, 1633, 1637, 1672, 8138, 8818, 1363, 
                                                                                                       1282, 1671, 1623, 1276, 1283, 1687, 1261, 1632, 1676, 1631, 
                                                                                                       8367, 8827, 1108, 1226, 1681, 1661, 1288, 1616, 1683, 1278, 
                                                                                                       1663, 1678, 1703, 8338, 8371, 1183, 1237, 1738, 1701, 1637, 
                                                                                                       1681, 1721, 1271, 1738, 1663, 1732, 8180, 8076, 1318, 1271, 
                                                                                                       1732, 1883, 1286, 1607, 1336, 1281, 1711, 1873, 1881, 8183, 
                                                                                                       1271, 1283, 1233, 1608, 1618, 1681, 1631, 1611, 1620, 1660, 
                                                                                                       1663, 1673, 1688, 8166, 1317, 1188, 1233, 1273, 1183, 1212, 
                                                                                                       1276, 1178, 1221, 1226, 1283, 8863, 8811, 1118, 1223, 1661, 
                                                                                                       1621, 1260, 1286, 1617, 1213, 1688, 1687, 1660, 8311), `Store 2` = c(1180, 
                                                                                                                                                                            811, 312, 1612, 1387, 878, 812, 883, 362, 768, 800, 760, 
                                                                                                                                                                            1180, 1021, 761, 1002, 1106, 1271, 337, 1113, 373, 833, 1012, 
                                                                                                                                                                            333, 303, 1166, 336, 708, 332, 1312, 1168, 838, 1010, 862, 
                                                                                                                                                                            773, 883, 861, 767, 1000, 1070, 636, 838, 1161, 1183, 887, 
                                                                                                                                                                            1001, 813, 331, 820, 738, 732, 1087, 333, 688, 810, 1311, 
                                                                                                                                                                            1183, 876, 338, 818, 816, 818, 816, 773, 333, 337, 888, 871, 
                                                                                                                                                                            1378, 1100, 1008, 368, 380, 883, 386, 872, 838, 363, 1102, 
                                                                                                                                                                            301, 831, 1133, 1331, 831, 333, 321, 338, 883, 832, 881, 
                                                                                                                                                                            1303, 766, 778, 773, 782, 731, 737, 801, 810, 816, 888, 883, 
                                                                                                                                                                            832, 811, 1820, 1000, 1136, 1270, 1718, 1188, 1873, 1162, 
                                                                                                                                                                            1136, 1130, 1178, 1110, 1371, 380, 703, 306, 1862, 1110, 
                                                                                                                                                                            873, 327, 837, 808, 817, 838, 726, 371)), row.names = c(NA, 
                                                                                                                                                                                                                                    -130L), class = c("tbl_df", "tbl", "data.frame"))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/wjfbr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wjfbr.jpg" alt="enter image description here"></a></p>
  
  <p>So my intention is to make automated selection of best three models like highlighted models above on basis on lowest MAPE error and calculate average by months of best three models for Store 1 and Store 2 like example below.<br>
  <a href="https://i.stack.imgur.com/wLxuw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wLxuw.jpg" alt="enter image description here"></a></p>
  
  <p>I tried with this code but I don't have good idea how to continue.</p>
  
  <pre><code># Arrange data by MAPE error
  Table_1a&lt;-data.frame(Table_1)%&gt;%
    select(X1,X2,value)%&gt;%
    arrange((value),.by_group = TRUE)
  
  # Select three best models
  Table_1b &lt;-data.frame(rbind(Table_1a[1:3, 1:3],Table_1a[10:13, 1:3]))%&gt;%
    select(X1,X2)%&gt;%
    group_by(X1,X2)
  
  # Тhis line does not work 
  
  Forecasting_Store_1&lt;-mutate(Table_2,
                              ifelse(Table_1b$X1==Table_2$Forecasting_model,Table_2$Forecasting_model,"")
                           )
  </code></pre>
  
  <p>So can anybody help me how to resolve this problem ?</p>