提取M4竞赛的年度数据

时间:2017-08-17 03:12:39

标签: r

我想提取M4比赛的年度数据。 对于M3和M1数据,我使用以下代码提取“年度”数据

library(Mcomp)
yearly_m1 <- subset(M1, "yearly")
yearly_m3 <- subset(M3, "yearly")

当我使用M4comp的跟随

library(M4comp)
yearly_m4 <- subset(M4, "yearly")

我收到错误消息。我想知道如何提取M4comp的年度数据。

1 个答案:

答案 0 :(得分:1)

使用它来汇总数据

if(!require("devtools")) install.packages("devtools")
library(devtools)

if(!require("M4comp2018")) devtools::install_github("carlanetto/M4comp2018")
library(M4comp2018)

data(M4)
df <- data.frame(matrix(ncol = 5, nrow = 100000))
colnames(df) <- c( "st", "n", "type", "h", "period")
df$st     <- unlist(Map(function(l) { as.character(l$st[[1]][1]) }, M4))
df$n      <- unlist(Map(function(l) { c(l$n[[1]][1]) }, M4))
df$type   <- unlist(Map(function(l) { as.character(l$type[[1]][1]) }, M4))
df$h      <- unlist(Map(function(l) { c(l$h[[1]][1]) }, M4))
df$period <- unlist(Map(function(l) { as.character(l$period[[1]][1]) }, M4))
M4.Summary <- df
rm(df, M4)

相关问题