Making a time series function

What we currently have:

ts_function <- function(ts_df, freq, start_year) { 

  ts_data <- ts(ts_df[,2:length(ts_df)], start=c(start_year, 1),frequency = freq) 




TS function do not have command for which M or Q to start from (year only). Example, something like this:

ts(1:10, frequency = 4, start = c(1959, 2)) # 2nd Quarter of 1959 print( ts(1:10, frequency = 7, start = c(12, 2)), calendar = TRUE) 
# print.ts(.) 
## Using July 1954 as start date: gnp <- ts(cumsum(1 + round(rnorm(100), 2)), start = c(1954, 7), frequency = 12) plot(gnp) # using 'plot.ts' for time-series plot

Source: ts function - RDocumentation

*this one isn't the function though


Might have to create 2 TS functions for Q and M separately *though going forward, more convenient to have only one TS function that constitutes Q and M together in one line lol

Perhaps you can pass the start argument to ts as the argument to your function instead of start_year.

1 Like