0

I am new to r and to this forum so sorry in advance if this question is annoying.

I am carrying out several regression models with code looking like this:

c250 <- lm(y ~ b1 + c + d + e)
c300 <- lm(y ~ b2 + c + d + e)
c350 <- lm(y ~ b3 + c + d + e)
c400 <- lm(y ~ b4 + c + d + e)
c450 <- lm(y ~ b5 + c + d + e)
c500 <- lm(y ~ b6 + c + d + e)

etc...

Is there a way to write this shorter?

Vidaps
  • 9
  • 1

1 Answers1

1
for(i in 1:6){
   assign(paste0("c",200+50*i), lm(y ~ get(paste0("b",i)) + c + d + e))
}

This should work

Acarbalacar
  • 714
  • 2
  • 7
  • 19