How to use multiple data to train a linear regression model in R

423 views Asked by At

I am building a linear regression model to predict 2015 values. I have data from 2013 and 2014. My question is, how can I use both the data from 2013 and 2014 to train my linear regression model in R? I have:

model1 = lm(x ~ y, data = data2013)

model2 = lm(x ~ y, data = data2014)


predictions1 = predict(model1, testdata)

predictions2 = predict(model2, testdata)

I was wondering if I could build a more accurate model using all the data I have. It would be something like this:

model1&2 = lm(x ~ y, data = data2013 & 2014)

Thank you in advance,

1

There are 1 answers

1
JasonAizkalns On BEST ANSWER

If the columns are exactly the same, you should be able to do something like this:

data_2013_and_2014 <- rbind(data2013, data2014)
new_model <- lm(x ~ y, data = data_2013_and_2014)

Lookup ?rbind for more details.