Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

how to apply a function on a list and return a vector?R

$
0
0

I am trying to create a vector with the sum of the forecasts created but the vector is only storing the last value, how to create a vector with each sum?

library(forecast)

setwd("C:\\Users\\Note\\Documents\\Ssl")
n <- dir(pattern = ".csv")
forecastOut <- lapply(n, function(x) {
  dat <- read.csv(x, sep=";", header = TRUE)
  predic <- auto.arima(dat[,1])
  forecast(predic, h = 4)
    }) 

names(forecastOut) <- n

for (i in forecastOut){
  sum<-c(sum(unlist((i[4]))))
 }   
>sum
[1] 2944.32
> class(forecastOut)
[1] "list"

Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>