0

I'm trying to make a function out of a section of code that gets run many times. It uses different columns for different use cases. The problem stems from needing to programmatically create a formula for lm()

arima_forecast = function(data_set, data_col, dependent_col){
    # ... Other code
    regTrain = lm(data_col~dependent_col, data=training_data)
    }

  data_set = # data.frame
  data_col = 'pos_qty'
  dependent_col = 'delivery_qty'
  data_set = arima_forecast(data_set, data_col, dependent_col)

Running that gives me the following error:

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels 

I've verified that it works properly if I use delivery_qty~pos_qty and could jerry-rig a paste() to do the formatting, but is there a better way?

dreyco676
  • 771
  • 1
  • 6
  • 11

0 Answers0