loop for regression lm(y~x)

Can someone please point me towards right direction, my current data looks like this =>

Meter= c( Meter1, Meter 2, Meter 3........Meter 1440)

and for each meter, I have monthly electricity consumption,

Cons=c ( 6623, 11285, 21785....) like this.

I would like to cerate a simple regression model for each meter Meter 1:

lm(Cons~ HDD), Meter2: lm( Cons~HDD)----Meter1140=lm( Cons~ HDD ) 

Please see below my code this gives me an error message of

Error in model.frame.default(formula = df$Cons ~ HDD, data = data.subset, : variable lengths differ (found for 'HDD')

Please can you advise where I'm doing wrong

mod.store<- list()
for (i in 1:unique(df$Meter)){ 

Thanks in advance!

I think you might want to look into this vignette: https://cran.r-project.org/web/packages/broom/vignettes/broom_and_dplyr.html It gives an example of exactly what you're asking.

1 Like

Thanks Steph for looking this I will check your link.

4 posts were merged into an existing topic: lm(y~x )model, R only displays first 10 rows, how to get remaining results see below

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.