Fpp2 output to data frame

I am trying to export a forecast from the fpp2 package to xlsx. How can I tell if the output from the forecast is a table that can be exported?

write.xlsx(zfc33, file = "wfc33.xlsx", asTable = TRUE)
Error in write.xlsx(zfc33, file = "wfc33.xlsx", asTable = TRUE) :
x must be a data.frame is asTable == TRUE

zfc33
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Jan 2020 1253714 1150022 1357406 1095131 1412298
Feb 2020 1304330 1154533 1454127 1075236 1533424
Mar 2020 1354945 1167700 1542191 1068578 1641313
Apr 2020 1405561 1185066 1626056 1068343 1742779
May 2020 1456177 1204960 1707393 1071974 1840379
Jun 2020 1506792 1226548 1787036 1078196 1935388
Jul 2020 1557408 1249352 1865464 1086277 2028539
Aug 2020 1608023 1273068 1942979 1095753 2120294
Sep 2020 1658639 1297492 2019786 1106313 2210965
Oct 2020 1709254 1322481 2096028 1117736 2300773
Nov 2020 1759870 1347929 2171811 1129861 2389879
Dec 2020 1810485 1373757 2247214 1142567 2478404
Jan 2021 1861101 1399903 2322299 1155760 2566442
Feb 2021 1911717 1426320 2397113 1169366 2654067
Mar 2021 1962332 1452968 2471696 1183327 2741337
Apr 2021 2012948 1479817 2546078 1197595 2828300
May 2021 2063563 1506841 2620285 1212130 2914996
Jun 2021 2114179 1534019 2694339 1226900 3001457
Jul 2021 2164794 1561332 2768257 1241878 3087711
Aug 2021 2215410 1588765 2842054 1257040 3173780
Sep 2021 2266025 1616307 2915744 1272366 3259685
Oct 2021 2316641 1643944 2989338 1287840 3345442
Nov 2021 2367256 1671669 3062844 1303447 3431066
Dec 2021 2417872 1699472 3136272 1319175 3516570

Use as.data.frame() before writing, like this:

library(forecast)
library(openxlsx)
zfc33 <- USAccDeaths %>% ets() %>% forecast()
zfc33 %>%
  as.data.frame() %>%
  write.xlsx(file = "wfc33.xlsx", asTable = TRUE)

Created on 2020-05-05 by the reprex package (v0.3.0)

I will try this out - thank you for the help!

That worked great. Thank you. I am digging in and working with other features of the package now.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.