title: Generating data with a loop to use the predict function in R
body: <p>I've built a model with numeric and factor variables to predict sales based on advertising with weekly data from 2017 to 2019 and I am trying to run a code that will predict the monthly sales for 2020, for each combination of variables.</p>
  
  <p>For that, I need to input the right factor variables, and I was wondering what would be the best way to go about it, here is what my regression looks like:</p>
  
  <pre><code>regads2 = lm(dolsales~flavour+brand+packaging+month+organization+manufacturer+region+displaydummie+addummie+maddummie+laddummie+discount5to10+discount10to15
              +discount15to20+discount20to25+discount25to30+discount30to35+discount35to40+discount40to45+discount45to50+
                discount50to55+discount55to60+discount60to65+discount65to70+discount70to75, na.action = na.exclude,data = df)
  </code></pre>
  
  <p>Each of the factor variables have many levels (from 5 to 30), while "discount" variables are dummies. I tried to write a loop that would generate the data based on the levels of variables and store them but I haven't been able to fully get there and I am finding myself a little stuck. Here is what I wrote so far (it is working for one variable, but not for many)</p>
  
  <pre><code>input &lt;- matrix(ncol= 1, nrow = nlevels(region))
  for(i in c(0:nlevels(region))) {
      working[i,] &lt;- levels(region)[i]
       }
  input
  </code></pre>
  
  <p>I imagine there is a simpler way to go about it.</p>
  
  <p>Thanks so much, I've been stuck on that for a good week now.</p>