---
title: "SML201 Precept 3, Spring 2020"
output:
  html_document: default
  pdf_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


Create and save the file `p3.R` on your computer.  The file `p3.R`, which should contain all the required functions.


### Problem 1: Conversion to Grade Points

Write a function named `num2GP` that takes in a numerical score in a range of 0-100, and returns the grade-point value that corresponds to that score. Use the table below (adapted from Princeton's table [here](https://registrar.princeton.edu/student-and-alumni-services/transcript-and-verification-services/calculate-your-gpa)), with 4.0 being the highest possible grade-point value. The conversion from scores to grade points should be done using


```{r, echo= F}
data.frame(grade = c("A ", "A-", "B+", "B ", "B-", "C+", "C ", "C-",  "D ", "F "),
           range = c("93-100", "90-92", "87-89", "83-86", "80-82", "77-79", "73-76", "70-72", "60-69", "0-59"),
           grade.point = c(4.0, 3.7, 3.3, 3.0, 2.7, 2.3, 2, 1.7, 1, 0))
```

For example, the value of `num2GP(90)` should be 3.7.

### Problem 2: Compute GPA

The following code can be used to define a data frame containing a student's scores.

```{r}
student.scores <- data.frame("course" = c("Math 12", "English 12", "Geography 10"),
                             "score"  = c(98, 90, 85))

```

Write a function named `student.GPA` that takes in a data frame in a format like the one of the data frame above, and returns the student's GPA. Use the function you wrote in Problem 1.

Note: the Grade Point Average (GPA) is the average of the grade point values of individual courses. For example, if Bob got a score of 90 in English and a score of 99 in French, that means Bob's English grade is A- and Bob's French grade is A, so that Bob's GPA is $(3.7+4.0)/2 = 3.85$. It is incorrect to try to compute the GPA by first averaging the scores to get $95.5$, and then converting the $95.5$ to a $4.0$.

### Problem 3: Compute GPA for every student

Now, consider tables in the following format

```{r}
scores <- data.frame( "name" = c("Bob", "Bob", "Bob", "Alice", "Alice", "Alice"),
                      "course" = c("Math 12", "English 12", "Geography 10", "Math 12", "English 12", "Geography 10"),
                      "score" = c(98, 90, 85, 100, 90, 95))
```

Write a function named `compute.student.GPAs` which takes in a data frame in the format like the data frame above, and returns a table that contains the GPAs of each student in the table. The name of the column you create should be `"GPA"`. (Note: you might *not* want to use the function from Problem 2 directly)



### Problem 4: Popular names over time (Challenge)

Write a function that finds the girl name that was in the top 10 most popular names in the largest number of years in the data frame `babynames`. In other words, imagine there is a top 10 list of names every year. You want to find the name that was in the top 10 the most often. This is analoguous to asking something like [Who is the actor with the most Oscar nominations](https://en.wikipedia.org/wiki/List_of_actors_with_two_or_more_Academy_Award_nominations_in_acting_categories) (guess before clicking the link!)
