1
votes

I'm trying to seasonally adjust over 100 times series using the 'seasonal' package. The seasonal package requires that the series be a ts object. I have a .csv file set up like so:

timeseriesA timeseriesB timeseriesC
obs1        obs1        obs1
obs2        obs2        obs2
.           .           .
.           .           .

The full file contains over 100 columns (I could also transpose the rows and columns if that's better). This lets me run the following:

library(seasonal)

data <- read.csv("...sa.csv")  # read csv file 

#Create time series from vectors in data
TimeSeriesA <- ts(asd$ag, start=c(1992, 1), end=c(2014, 4),frequency=4) 
TimeSeriesB <- ts(asd$cons, start=c(1992, 1), end=c(2014, 4), frequency=4) 
TimeSeriesC <- ts(asd$mfg, start=c(1992, 1), end=c(2014, 4), frequency=4) 

datalist <- list(TimeSeriesA=ag, TimeSeriesB=cons,TimeSeriesC=mfg)

#seasonally adjust the time series in datalist

ll <- lapply(datalist, function(e) try(seas(e)))

is.err <- sapply(ll, class) == "try-error"
ll[is.err]

finalsa<-do.call(cbind, lapply(ll[!is.err], final))
finalsa

This gives me three seasonally adjusted series, but I need 100.

I'm trying to figure out how to efficiently take my 100 series from my .csv file, convert them to ts in R, and put them in the list to be seasonally adjusted.

Any help would be greatly appreciated! I'm new to R and still trying to learn it's data manipulation and transformation techniques.

1

1 Answers

0
votes

The first part of the problem can be solved using lapply(), in the same way as for the seasonal adjustment, e.g.:

data <- read.csv("sa.csv")
datalist <- lapply(data, function(t) ts(t, start=c(1992, 1), end=c(2014, 4),frequency=4))

The seasonal adjustments should then work as described in the question.