# How can I predict values from new inputs of a linear model in R?

I've created a linear model in R: mod = lm(train_y ~ train_x). I want to pass it a list of X's and get its predicted/estimateed/forecasted Y. I looked at predict(), but I think that is for something else, or I just don't know how to use it.

I'm guessing by taking the coefficients of my model, I could manually plugin the test_x variables one-by-one, and get a predicted Y, but I'm guessing there is a more efficient way to do this.

If you want the predicted values for train_x = 1, 2, and 3, use predict(mod, data.frame(train_x = c(1, 2, 3))).