Create and save the file p2.R on your computer. The file p2.R, which should contain all the required functions, should be submitted on Blackboard once you have completed the required functions. You must work with one partner. You should work collaboratively. Both partners are responsible for being able to explain the work that’s been done to the preceptor. Additionally, work submitted on Blackboard will be graded for correctness. Only one of the partners should submit the code on Blackboard.

The file p2.R should have include the following code, with the NetIDs of the two partners substituted in:

student.netid.1 <- "netid1"
student.netid.2 <- "netid2"
assignment <- "precept2"

In addition, a comment should contain the full names of the partners.

Before submitting, please make sure that check2.R runs without error. However, note that check2.R might not completely verify that your submission is correct – it is your job to test your functions.

Some of you will be tempted to use for and while-loops to solve some of the problems below (if you’ve used those before). Please don’t do this – the goal here is to try to use R the way professional data scientists use it, which usually means no loops.

Problem 1: Conversion to Grade Points

Write a function called 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 second table here, with 4.33 being the highest possible grade-point value.

Problem 2: Compute GPA

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

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

Write a function called StudentGPA 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.

Problem 3: Compute GPA for every student

Now, consider tables in the following format

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 called ComputeStudentGPAs 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: ggplot (not for submission on Blackboard)

Pick an appropriate graph from the R Graph Gallery to visualize some aspect of the babynames dataset, and then visualize babynames using that graph in ggplot2