forked from cis-ds/course-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw03-programming.Rmd
53 lines (35 loc) · 4.12 KB
/
hw03-programming.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
title: "Homework 03: Programming in R"
output: html_document
---
# Overview
Due before class Wednesday October 19th.
# Fork the `hw03` repository
Go [here](https://github.com/uc-cfss/hw03) to fork the repo for homework 03.
# Part 1: Programming exercises
1. Compute the mean of every column in `mtcars`.
1. Write code that uses a `for` loop to do this task.
1. Write code that uses one of the `map` functions to do this task.
1. Compute the number of unique values in each column of `iris`.
1. Write code that uses a `for` loop to do this task.
1. Write code that uses one of the `map` functions to do this task.
1. [Pythagorean theorem](https://en.wikipedia.org/wiki/Pythagorean_theorem)
$$a^2 + b^2 = c^2$$
* Write a function that, given the lengths of two sides of the triangle, calculates the length of the third side
* This function should be flexible - that is, the function works if I give it values for $a$ and $b$, or $b$ and $c$, or $a$ and $c$
* If the user only provides the length of one side, the function should [throw an error with `stop()`](http://r4ds.had.co.nz/functions.html). Likewise, if the user provides the lengths of all three sides, the function should throw an error.
* If the user provides any values other than numeric values, the function should throw an error
# Part 2: Using programming in data analysis
The World Bank publishes extensive socioeconomic data on countries around the world. In the `data_world_bank` folder, I have downloaded the World Bank's complete economic indicators for each country that is currently a member of the [United Nations Security Council](http://www.un.org/en/sc/members/).
In order to analyze the data, you first need to import it. Each country's data is stored in a separate `.csv` file. You should write a function which uses one argument (the filepath to the data file). Given this path, the function should read and tidy the country data, and return the cleaned data frame as the output. Remember the rules for a tidy data frame:
1. Each variable must have its own column.
1. Each observation must have its own row.
1. Each value must have its own cell.
Since the World Bank has hundreds of indicators, your function should pare this down to only the handful of variables you intend to analyze. Once you have written this function, demonstrate that it works by importing the data files and combining them into a single data frame using either a `for` loop or a `map` function.
Once you have the data imported, you should write a brief report exploring and analyzing at least [two variables in the data](http://data.worldbank.org/indicator). You should explore both variance and covariance, and present your results and analysis in a coherent and interpretable manner. The main point is that your report should not just be code and output from R - you also need to include your own written analysis. Submitting the report as an [R Markdown document](http://rmarkdown.rstudio.com/) will make this much easier.
# Submit the assignment
Your assignment should be submitted as two RMarkdown documents. Follow instructions on [homework workflow](hw00_homework_guidelines.html#homework_workflow). As part of the pull request, you're encouraged to reflect on what was hard/easy, problems you solved, helpful tutorials you read, etc.
# Rubric
Check minus: Displays minimal effort. Doesn't complete all components. Code is poorly written and not documented. World Bank analysis is slapped together, or just contains code and output. No history of commits to document work.
Check: Solid effort. Hits all the elements. No clear mistakes. Easy to follow (both the code and the output). Nothing spectacular, either bad or good.
Check plus: Functions are written succinctly and comprehensibly. Error checks are incorporated into functions as appropriate. Code is written parsimoniously and properly formatted. Frequent use of commits to track changes. Exploratory analysis demonstrates thought and consideration of the relationships. Graphs and tables are properly labeled. Descriptive text is incorporated into the World Bank analysis that explains what you are examining and how to interpret the results.