croston方法应如何应用于数据集

croston方法应如何应用于数据集,r,forecast,R,Forecast,我有数据显示每月250种产品的需求。 我在R中导入了数据。我想将croston方法应用于此数据集并将结果写入文件,但我不知道如何逐行应用公式并写入文件。我有这样的表格: product D1 D2 D3 D3 D4.... DV400767 6 1 3 1 17 0 5 0 0 1 0 3 0 DV557119 6 3 2 1 16 0 0 0 0 0 1 0 10 DV596323

我有数据显示每月250种产品的需求。
我在R中导入了数据。我想将croston方法应用于此数据集并将结果写入文件,但我不知道如何逐行应用公式并写入文件。我有这样的表格:

     product   D1 D2 D3 D3 D4....
     DV400767  6  1  3  1 17  0  5  0   0   1   0   3   0
     DV557119  6  3  2  1 16  0  0  0   0   0   1   0  10
     DV596323  0  0  2  1  2  0  2  9   0   3   0   0   2
我试图通过这些代码找到结果,但是crost函数只应用了一列

data<-read.csv("data.csv", header=TRUE)
crost(data, h=1,w=0.3, init=c(1,1))

数据您可以转换
数据。帧
并使用
应用
功能:

data <- read.table(text = "
DV400767  6  1  3  1 17  0  5  0   0   1   0   3   0
DV557119  6  3  2  1 16  0  0  0   0   0   1   0  10
DV596323  0  0  2  1  2  0  2  9   0   3   0   0   2")
names(data) <- c("product", paste0("D", 1:13))

rownames(data) <- data$product
data_t <- as.data.frame(t(data[, -1]))

library(tsintermittent)
models <- apply(data_t, 2, crost, h = 1, w = 0.3, init = c(1,1))

# Print information of the fist product: DV400767
list(names(data_t)[1], models[[1]])

欢迎来到SO。请看,学习如何提出一个好的问题,这将得到一个好的答案。
[[1]]
[1] "DV400767"

[[2]]
[[2]]$`model`
[1] "croston"

[[2]]$frc.in
 [1]          NA 2.750000178 2.531250137 2.602272849 2.317170902 5.293018040 5.293018040 4.268771415 4.268771415 4.268771415
[11] 2.537046096 2.537046096 2.230787775

[[2]]$frc.out
[1] 2.230787775

[[2]]$weights
[1] 0.3 0.3

[[2]]$initial
[1] 8.249999748 2.999999714

[[2]]$components
[[2]]$components$`c.in`
           Demand    Interval
 [1,]          NA          NA
 [2,] 8.249999748 2.999999714
 [3,] 6.074999823 2.399999800
 [4,] 5.152499876 1.979999860
 [5,] 3.906749913 1.685999902
 [6,] 7.834724939 1.480199931
 [7,] 7.834724939 1.480199931
 [8,] 6.984307458 1.636139952
 [9,] 6.984307458 1.636139952
[10,] 6.984307458 1.636139952
[11,] 5.189015220 2.045297966
[12,] 5.189015220 2.045297966
[13,] 4.532310654 2.031708576

[[2]]$components$c.out
          Demand    Interval
[1,] 4.532310654 2.031708576

[[2]]$components$coeff
[1] 1