I got this advice from someone when I needed to know how to apply a procedure on a subgroup of subjects within the analysis dataset. Thanks.
library(dplyr) library(magrittr)
ols_result <- data %>% dplyr::filter(year=1) %>% lm(y~x,.) summary(ols_result)
dplyr::filter(year==1)