I am trying to run the seasonal adjustment function seas() from the seasonal package on R. My code is as follows:
#import and load required packages
#install.packages("seasonal")
#install.packages("tidyverse")
#install.packages("parsedate")
library(seasonal)
library(tidyverse)
library(parsedate)
# import datarange from excel
#data <- AirPassengers #temp
data <- read.csv('C:/Users/user/Desktop/x13arima/temp.csv')
# clean imported data and standardise date format
data[[1]] <- parse_date(data[[1]])
data[[1]] <- format(data[[1]],"%Y-%m")
# reverse order of data to descending
data <- map_df(data,rev)
data <- data.frame(data)
data[,2] <- as.numeric(data[,2])
#specify the start date of time series
start_date = str_split_1(data[1,1],"-")
#convert data to time series
series <- ts(data[[2]],frequency = 12, start = start_date)
# perform seasonality adjustment on cleaned data
adjusted = seas(series)
# select subset to export from analysed data
export = adjusted[["data"]]
#export = subset(export,select = c("final","seasonal"))
# export dataframe
write.csv(export,file="C:/Users/user/Desktop/x13arima/adjusted_data.csv", row.names=FALSE)
This works without problems when I run the script without the lines
# reverse order of data to descending
data <- map_df(data,rev)
data <- data.frame(data)
data[,2] <- as.numeric(data[,2])
where I reverse the order of my data frame and ensure the format of the new dataframe is the same as before. When I run the script with this code block, I get the error:
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:\Users\user\AppData\Local\Temp\RtmpcVfiCB\x1375d824d446cd/iofile.est': No such file or directory
My data has the following format:
ranging from different dates from 30/11/2018 to 31/10/2023.
I can't find anything online relating to this, and am unsure how to solve this. Has someone had a similar problem before?
I've tried several ways of reversing the rows in the data frame, and I have also ensured that the new data frame has the exact same format as the old one. The time series 'series' is also the same format as before, and plotting this gives the expected result.