How to add repeated measures in lm(e) ?

I have a question about analysing with repeated measures. So i made a model of my dependent variable (S, stands for adjustment, is numeric), my independent variable (populair_friend condition, is factor/categorical) and i added two covariates (gender/geslacht, categorical, and popularity goal, numeric).

So this is my code:

make model of variables

model3 <- lm(final_data$S ~ final_data$populair_vriendfinal_data$pop_doel+ final_data$populair_vriendfinal_data$geslacht, data=final_data)
summary(model3) # show results

repeated measures ancova

res.aov3 <- aov(model3, data = final_data, dv = final_data$S, wid = final_data$participant_ID, within = final_data$populair_vriend)
summary(res.aov3)

But now my question is: I want to insert the within grouping already in my model, in stead of in my ancova. Does anybody knows how to do this?

Hi @sophie_becking , remember put a reproducible example of data for better help.

FAQ: What's a reproducible example (`reprex`) and how do I create one?](FAQ: What's a reproducible example (`reprex`) and how do I create one?)

Check this links for ancova: