Hi Teun,
In the dataset I created there's a column forecasting_method
where you can act upon. In your dataset it is missing because you have a 'non-tidy' dataset.
See below how you could 'fix' it
library(tidyverse)
df <- structure(list(MAE = c(5088.79487179487, 1519.16666666667, 3319.16666666667,
1647.37550817214, 1831.48661617148, 1936.12400158197, 46.8793232245741,
3605.31989627243, 28618.3341970992, 3485.67626446658, 3548.85326904943
),
RMSE = c(5385.92567587919, 1797.19137359752, 3518.98917778008,
2008.47348725738, 2045.7584641563, 2016.76935543134, 3543.89304061995,
4189.20277632183, 51736.605754416, 4155.50054910879, 4177.41498689721
),
MAPE = c(78.4664901470441, 30.2031258777449, 57.3489202049514,
33.8897040352631, 34.497985767558, 34.1979173250488, 3125.78437656345,
56.214461999567, 638.54777455328, 54.2022817924072, 50.1330768372487
),
MASE = c(6.27485518749612, 1.87324328827628, 4.09277455688669,
2.03133413973946, 2.25835656257448, 2.38738208967683, 3.85432009039803,
4.44562235728883, 35.2884931144467, 4.29809303402039, 4.37599488798082
)
),
class = "data.frame",
row.names = c("Mean", "Naive", "Snaive", "Drift", "addf", "mulf", "fit_ar", "fit_sar", "txt", "txc", "txtotaal")
)
## dataset is not tidy as it contains values as a rowname and not as a separate column
## The values of the rownames appears to be missing
df %>% glimpse()
#> Rows: 11
#> Columns: 4
#> $ MAE <dbl> 5088.79487, 1519.16667, 3319.16667, 1647.37551, 1831.48662, 19...
#> $ RMSE <dbl> 5385.926, 1797.191, 3518.989, 2008.473, 2045.758, 2016.769, 35...
#> $ MAPE <dbl> 78.46649, 30.20313, 57.34892, 33.88970, 34.49799, 34.19792, 31...
#> $ MASE <dbl> 6.274855, 1.873243, 4.092775, 2.031334, 2.258357, 2.387382, 3....
## let's convert the rownames to a new column and specify the new column name
df_tidy <- df %>%
rownames_to_column(var = "forecasting_method")
df_tidy %>% glimpse
#> Rows: 11
#> Columns: 5
#> $ forecasting_method <chr> "Mean", "Naive", "Snaive", "Drift", "addf", "mul...
#> $ MAE <dbl> 5088.79487, 1519.16667, 3319.16667, 1647.37551, ...
#> $ RMSE <dbl> 5385.926, 1797.191, 3518.989, 2008.473, 2045.758...
#> $ MAPE <dbl> 78.46649, 30.20313, 57.34892, 33.88970, 34.49799...
#> $ MASE <dbl> 6.274855, 1.873243, 4.092775, 2.031334, 2.258357...
## now the dataset can be considered as tidied and will be much easier to work with
df_tidy %>%
pivot_longer(cols = MAE:MASE,names_to = "col_name", values_to = "value") %>%
group_by(col_name) %>%
mutate(lowest_value = min(value)) %>%
filter(value == lowest_value) %>%
select(col_name, forecasting_method, lowest_value)
#> # A tibble: 4 x 3
#> # Groups: col_name [4]
#> col_name forecasting_method lowest_value
#> <chr> <chr> <dbl>
#> 1 RMSE Naive 1797.
#> 2 MAPE Naive 30.2
#> 3 MASE Naive 1.87
#> 4 MAE fit_ar 46.9
Created on 2021-03-02 by the reprex package (v1.0.0)
I can highly recommend the following book if you want to get a better understanding of the tidyverse approach.