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?

0

1 Answer 1

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

This should work

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.