Find us on GitHub

Week 10: Still more R

See the bottom of this page for this weeks Challenge.

Preparation

We will use the same project directory as week 9. If you need to reconstruct that project directory and the data in it, here are the instructions. You will also want to install the lubridate package using install.packages("lubridate"), before following any of the videos below.

Controlling what happens in your script

Sometimes you want R to do different things depending on the value of an object. We use if() statements to do this. Or you might need to repeat a task using a for() loop.

Plotting error bars

Perhaps the most important thing you can do in Science is quantify how certain you are. In plots we do this with error bars. ggplot2 has several ways to do error bars.

Assignment

The file for this weeks assignment will be a commented R script. The file should be saved with a name like yourlastname_week10.R, and uploaded as an attachment. At the top of the file write a comment (start the line with #) with the week number and your name on one line. If none of that makes sense, go watch the start of the video for subsetting vectors.

  • Do the Advanced Challenge at the bottom of this page. You can either change back to the my_project project created in week 6, or download the gapminder data again into the week9 project.

I should be able to run your script from the main directory of the project created in week 9 using source("code/yourlastname_week10.R") from a clean start of R. To test your code to make sure it works without errors, first click on the Session menu, and choose Restart R. Then open your file and click the source button in the top right corner. This will load your file and run it; any output to the console is suppressed. Check the date and time of the saved image file to make sure the script ran correctly.

This challenge is due on Friday of Week 10 (Mar 18) at 5 pm. Late assignments will receive a score of zero unless prior approval is granted.