You've been given the correct answers. Lets have a look at why yours doesn't work.
for does not take a data argument.
data %>% func(x,y,z) is equivalent to
func(data, x, y, z). So what you wrote is equivalent to
for (gapminder, i in 1952:2007) which makes no sense.
i==num(i) is a tautology.
i is taken from a range of integers (
1952:2007), so it is always an integer and will always match itself cast as double precision floating point number (
numeric), regardless of what the actual number is.
3] your code does not subset the dataframe anywhere.
Maybe you should familiarize yourself more with basic R and get the step-by-step logic fundamentals clear in your head before rushing to do
more complex stuff with dplyr.
For future reference, you should include any warning and error messages your code causes when asking for help.