I have 5 tibbles for successive years 2016 to 2020. I am doing the same thing to each of the sets of tibbles so I want to use a for-loop rather than copying and pasting the same code 5 times. I have named the tibbles in the following way with the final number indicating the year of the data:
- alpha_20
- beta_20
- gamma_20
- delta_20
- epsilon_20
My thought was to do this:
for (i in 16:20) {
alpha_a_[i]<-alpha_[i]%>%
mutate(NEWVAR=1+OLDVAR)%>%
select(NEWVAR, VAR2, VAR3)
beta_a_[i]<-beta_[i]%>%
group_by(PIN)%>%
summarize(sum(VAR1))
# and so on for all 5 tibbles
}
But I think I am not calling the tibble correctly because the code breaks at the first mutate. I can't seem to figure out how to instruct it to take the tibbles ending in "16" and then the tibbles ending in "17" and so on.