0

Please, help mewith my homework. I have a dataset with information about Sales of 10 different stores. I should to predict the sales on the 2 monthes. For my model I used the column "Open" - at what day the store is open or closed; and "Promo" - if store have a promotion or not. I've built an lm model:

m.s<-lm(Sales~Open+Promo, data)
sale<-predict(m.s, newdata, ...)

This model works for 1 store, but how i can build this model for all 10 stores and predict the sales?

Personally I was thinking something like:

bn<- for(Store in 1:10 )
  {m.sales7<-lm(Sales~Open+Promo, data)}

But it doesn't work/

Dasha
  • 1

1 Answers1

1

Without seeing your data, I can't help you with the actual modeling, but your loop should look something more like this:

for(Store in 1:10 ) {
   model[Store] <- lm(Sales~Open+Promo, data)
}

This creates a vector of all your store models. Be sure to change your data source (data) with each iteration, too to match the correct store's data. Again, without seeing your data, I can't really help you set that up.

To run predictions, access the models with model[1] ... model[10].

WillardSolutions
  • 2,316
  • 4
  • 28
  • 38
  • Actually this is unlikely to work. `model` should be a list here `model <- list()` and you would need to store elements in it using `model[[Store]]<-`, not `model[Store]<-` – MrFlick May 17 '16 at 21:23