Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is that you use <code>ddply(</code>, where the first <code>d = datatype of input = data.frame</code> and the second <code>d = datatype of output = data.frame (again)</code>. However, the input you are providing <code>retail[, 2:ncols]</code> is not a <code>data.frame</code>. </p> <pre><code>class(retail) [1] "mts" "ts" </code></pre> <p>Instead, what you could do is <code>ldply</code> which takes a <code>list</code> as input, runs your function and tries to output a <code>data.frame</code>. You could accomplish in this manner.</p> <pre><code>require(forecast) require(plyr) retail &lt;- read.csv("http://robjhyndman.com/data/ausretail.csv",header=FALSE) retail &lt;- ts(retail[,-1],f=12,s=1982+3/12) ns &lt;- ncol(retail) h &lt;- 24 plyr.fcast &lt;- t(ldply(1:ns, function(idx) { c(forecast(retail[, idx], h = h)$mean) })) </code></pre> <p>This takes quite a lot of time. If you want to run in parallel (assuming you're running on a cluster/machine with many cores), then you can install the package <code>doMC</code> and then use it as follows:</p> <pre><code>require(doMC) registerDoMC(20) # BEWARE: use it if you have 20 processors available!! plyr.fcast &lt;- t(ldply(1:ns, function(idx) { c(forecast(retail[, idx], h = h)$mean) }, .parallel = TRUE)) </code></pre> <p>The transpose gives the results equal to <code>fcast</code> and also type-casts the <code>data.frame</code> output from <code>plyr</code> to a <code>matrix</code>. So, you can use the same <code>write</code> syntax to write to file.</p> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload