Last active
March 2, 2018 18:05
-
-
Save jmg/b80d53ee28aed6a848a244491be0e552 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildFormula <- function(dataset, LTerms, useTrend=FALSE, useSeason=FALSE) { | |
lLen <- length(LTerms) | |
for (i in 1:lLen) | |
assign(paste("fact", i, sep=""), L(dataset, LTerms[i])) | |
factors = array() | |
for (i in 1:lLen) | |
factors[i] <- paste("fact", i , sep="") | |
formTerms <- paste("dataset ~ ") | |
if (useTrend) { | |
trendFactor <- trend(dataset) | |
factors <- c("trendFactor", factors) | |
} | |
if (useSeason) { | |
seasonFactor <- season(dataset) | |
factors <- c("seasonFactor", factors) | |
} | |
form = as.formula(paste(formTerms, paste(factors, collapse="+"))) | |
return(form) | |
} | |
#call example | |
form <- buildFormula(sales_aggr, c(1,6,12), useTrend=TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment