let's assume I have a dataset similar to this:
df1 <- data.frame(age==1:10, year==2004)
df2 <- data.frame(age==1:10, year==2005)
df3 <- data.frame(age==1:10, year==2006)
df <- rbind(df1,df2,df3)
df <- df %>% mutate(group=case_when(age %in% c(1:3) & year==2004 ~ "A"))
I want those who are 2, 3 and 4 years old in 2005 to be in group A, and those who are 3, 4 and 5 years old in 2006 to be in group A. How do I do this using a for-loop?