extracting residuals from several Regression by using Loops

hello friends :slightly_smiling_face:

I need to extract the residuals from a simple Linear regression lm(y~x) , but the challenge is I need to run separate regression for each category for each year , then after combining the residual beside each observation .

this is a sample from the data I have 8 categories need to be run for 2 years , we need to run 16 regression , the real sample is for 20 years and for around 40 categories .

below are the data , your help is really appreciated :heart_hands:

Thank you

in general the pattern is.
1 ) write code to do the thing once
2) make a function out of that
3) iterate through it with lapply or something from the purrr family.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.