# 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))).
{"ft_lang_label":"__label__en","ft_lang_prob":0.96960765,"math_prob":0.7234752,"size":434,"snap":"2020-34-2020-40","text_gpt3_token_len":110,"char_repetition_ratio":0.09767442,"word_repetition_ratio":0.0,"special_character_ratio":0.25345623,"punctuation_ratio":0.10638298,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98489565,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-08-15T05:53:25Z\",\"WARC-Record-ID\":\"<urn:uuid:e7cd233e-d113-4249-97f6-d28d837e301d>\",\"Content-Length\":\"121660\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:444fd701-578c-4b71-8fbf-07d71f825b24>\",\"WARC-Concurrent-To\":\"<urn:uuid:3f28ca36-6f59-46ac-98a9-e3d171cf967a>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://stats.stackexchange.com/questions/13880/how-can-i-predict-values-from-new-inputs-of-a-linear-model-in-r/13881\",\"WARC-Payload-Digest\":\"sha1:VUMCUMYMWPG5PVPRHAQPVGFMQ7X465D5\",\"WARC-Block-Digest\":\"sha1:YVVWEMQJDRKJ3OFKOXF23AVELZ52RMVX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-34/CC-MAIN-2020-34_segments_1596439740679.96_warc_CC-MAIN-20200815035250-20200815065250-00270.warc.gz\"}"}