R/tsCompleteYears.r

Defines functions tsCompleteYears

Documented in tsCompleteYears

#'@title  Trim a monthly time series object to so that partial years are removed
#'
#'@details This function is only supported for monthly time series
#'
#'@param tsData  A time series object
#'
#'@return A time series with partial years removed.
#'
#'@export

tsCompleteYears <- function(tsData)
{

	if (frequency(tsData) != 12) {
		stop("This function is only supported for monthly time series.")
	}

	origStartMonth <- start(tsData)[2]
	origStartYear  <- start(tsData)[1]
	origEndMonth   <- end(tsData)[2]
	origEndYear    <- end(tsData)[1]

	newStartMonth <- 1
	newEndMonth   <- 12

	tsObj <- tsData

	if (origStartMonth > 1) tsObj <- window(tsObj, start=c(origStartYear+1,newStartMonth))
	if (origEndMonth < 12)  tsObj <- window(tsObj, end=c(origEndYear-1,newEndMonth))

	return (tsObj)
}

Try the Achilles package in your browser

Any scripts or data that you put into this service are public.

Achilles documentation built on May 31, 2023, 8:57 p.m.