r-novice-gapminder
r-novice-gapminder copied to clipboard
Episode 7 (control flow), Challenge 1
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.
I think that %in% would be better to introduce as it can be a more powerful tool in the future than any.
I am inclined to add the %in%
solution as a third option.
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