【发布时间】:2015-05-14 06:00:11
【问题描述】:
我需要将向量元素的所有组合应用于特定函数,并将这些元素也用作该函数的输入。我希望它有点快,但到目前为止,任何组合应用和它的不同口味都被证明是徒劳的。
简而言之,我有一个时间序列,我需要拟合一个 ARIMA 模型来描述这个过程。包 stats 中的函数 arima 需要一组输入,因为我不想手动执行此操作,因此可以为我执行此操作的函数似乎是有序的。
到目前为止,我已经尝试过:
library(stats)
#need a vector to cycle and use as inputs in the function
nums <- c(0:3)
#random time series
x <- rnorm(1000,mean=1,sd=1)
#attempt 1
lapply(nums, arima(x, order=c(nums,nums,nums)))
#attempt 2
lapply(nums, arima(x))
#attempt 3
#create another vector, as to start cycle with 1 rather than 0
nums2 <- c(1:3)
lapply(nums2, arima(randomtimeseries, c(nums, nums, nums)))
必须以这种方式完成,因为这是作为 cron 作业运行的,因此用户无需添加任何输入以简化上述过程。
【问题讨论】:
-
那么,您想运行
arima和order = c(0, 1, 2),然后是order = c(0, 2, 1),然后是1, 2, 0,然后是1, 0, 2,等等? -
是的。通过向量给出的所有可能组合运行 Funktion。
标签: r functional-programming combinations