—
title: “Practice Exam Part 1 – Solution”
author & honor code compliance: “
date: “
output: html_document
#Your Name and NetID in line 2 will indicate complaince with Fuqua Honor Code (https://www.fuqua.duke.edu/honorcode) for the final exam.
—
“`{r setup, include=FALSE}
# Chunk 1. Generated knit setting
knitr::opts_chunk$set(echo = TRUE)
“`
## R Markdown
Reminder: This is a Practice Exam Part 1 for the R Proficiency Exam Part 1.
Goals:
1. Prepare for the R Proficiency Exam
Tips for the exam:
1. Your Name and NetID in line 3 will indicate complaince with Fuqua Honor Code (https://www.fuqua.duke.edu/honorcode) for the final exam. You must submit with that to received credit for this exam.
2. The exam is open book/internet/notes/etc. However, you can’t discuss with any living being except Dr. Salman Azhar.
3. I will use datasets similar to the ones used in this practice.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
*Note: Numbering corresponds to chunk numbers. Chunk #1 specified knitting*
*2. Run the following code chunk to initialize four variables.*
*These variables contain the flight times (in minutes) for several flights from RDU to JFK, LHR, ATL, and ORD, respectively.*
“`{r}
# Do not modify anything in this code block
flightMinutesJFK <- c(99, 81, 88, 80, 81, 87, 85, 88, 95, 95)
flightMinutesLHR <- c(761, 770, 773, 746, 758, 750, 738, 755, 725, 776)
flightMinutesATL <- c(77, 76, 73, 73, 78, 79, 76, 77, 78, 79)
flightMinutesORD <- c(107, 101, 101, 109, 109, 105, 108, 101, 101, 101)
```
*3. Examine the structure and statistical summary of flightMinutesJFK.*
```{r}
```
*4. Print the type of flightMinutesJFK and the number of elements in it.*
```{r}
```
*5. Find the median duration of a flight from RDU to JFK.*
```{r}
```
*6. Combine all flight vectors into a matrix called flightMatrix, that has a column for each observation and a column for each airport.*
*Print the result to validate your code.*
```{r}
```
*7. Rename the columns with the three letter airport codes for JFK, LHR, ATL, ORD.*
*Print the result to validate your code.*
```{r}
```
*8. Using a for-loop that iterates through each column of flightMatrix (regardless of the number of columns in flightMatrix), add a row at the bottom of this matrix that gives you the shortest flight to each airport (in minutes).*
```{r}
```
*9. Using a for-loop that iterates through each column of flightMatrix (regardless of the number of columns in flightMatrix), compute a vector timeBand (of type chr) that can have three possible values: short, medium, long.*
*timeBand is based on minValue: short for less than 100 minutes, medium for over 100 and under 300 minutes, long for over 300 minutes.*
```{r}
```
*10. Add a row durationBand of type ordered factor that can have three possible values: short, medium, long.*
*The value of durationBand are based on timeBands*
*Hint: Do this in two steps (define durationBands, add to flightMatrix).*
*Tip: Print flightMatrix to check your answer.*
```{r}
```
*11. Convert flightMatrix to a dataframe and then add a row timeBand to flightMatrix. Also, print out the structure of flightMatrix before and after adding the new timeBand row, explain any change(s) in the types of flightMatrix's columns. *
*Tip: Print the result to check your answer.*
```{r}
```
*12. Knit to html after eliminating all the errors. Do not worry about minor formatting issues.*