##### Remember to change the author: field on this Rmd file to your own name.

For the first two problems we’ll use the Cars93 data set from the MASS library.

library(tidyverse)
library(MASS)

#### 1. Manipulating data frames

There are certain situations where we want to transform right-skewed data before analysing it. Taking the log of right-skewed data often helps to make it more normally distributed.

Here are histograms of the MPG.highway and MPG.city variables.

qplot(MPG.city, data = Cars93, bins = 10)

qplot(MPG.highway, data = Cars93, bins = 10)

(a) Do the city and highway gas-mileage figures appear to have right-skewed distributions?

(b) Use the mutate() and log() functions to create a new data frame called Cars93.log that has MPG.highway and MPG.city replaced with log(MPG.highway) and log(MPG.city), respectively.

# Edit me

(c) Run the histogram plotting commands again, this time using your new Cars93.log dataset instead of Cars93.

# Edit me

(d) Do the distributions appear less skewed than before?

#### 2. Table function

(a) Use the table() function to tabulate the data by DriveTrain and Origin.

# Edit me

(b) Repeat part (a), this time using the count() function.

(c) Does it looks like foreign car manufacturers had different Drivetrain preferences compared to US manufacturers?

#### 3. Functions, lists, and if-else practice

(a) Write a function called isPassingGrade whose input x is a number, and which returns FALSE if x is lower than 50 and TRUE otherwise.

# Edit me

(b) Write a function called sendMessage whose input x is a number, and which prints Congratulations if isPassingGrade(x) is TRUE and prints Oh no! if isPassingGrade(x) is FALSE.

# Edit me

(c) Write a function called gradeSummary whose input x is a number. Your function will return a list with two elements, named letter.grade and passed. The letter grade will be "A" if x is at least 90. The letter grade will be "B" if x is between 80 and 90. The letter grade will be "F" if x is lower than "80". If the student’s letter grade is an A or B, passed should be TRUE; passed should be FALSE otherwise.

# Edit me

To check if your function works, try the following cases:

x = 91 should return

## $letter.grade ## [1] "A" ## ##$passed
## [1] TRUE

x = 62 should return

## $letter.grade ## [1] "F" ## ##$passed
## [1] FALSE