r-novice-gapminder icon indicating copy to clipboard operation
r-novice-gapminder copied to clipboard

Episode 7 (control flow), Challenge 1

Open mstrimas opened this issue 4 years ago • 3 comments

This challenge asks student to print an informative message if there are any records in gapminder for the year 2002. Two solutions are provided, one using any(gapminder$year == 2002) (note any() isn't introduced until later in that episode) and one much more complicated one involving counting the number of rows for the year 2002. It seems to me the only reasonable way to do this is with %in%, which is much simpler and uses a function that was introduced in the previous episode. I propose the solution should be:

if (2002 %in% gapminder$year) {
  print("Record(s) for the year 2002 found.")
}

I could see an argument for keeping the approach using any() as an alternative.

mstrimas avatar Jan 12 '20 14:01 mstrimas

I think that %in% would be better to introduce as it can be a more powerful tool in the future than any.

jam2094547 avatar Jun 20 '20 18:06 jam2094547

I am inclined to add the %in% solution as a third option.

jcoliver avatar Jun 23 '20 16:06 jcoliver

I'd like to self-assign this issue if it's acceptable. I also noticed %in% is not mentioned in the reference page: https://swcarpentry.github.io/r-novice-gapminder/reference.html

So I might submit this as well during the PR.

Thanks,

Ammar

ammaraziz avatar Apr 27 '21 02:04 ammaraziz