- [Quick R](https://www.statmethods.net/r-tutorial/index.html)
- [Rstudio cheatsheet](https://www.rstudio.com/resources/cheatsheets/)
- [Rstudio for beginners](https://education.rstudio.com/learn/beginner/)

# Part 1: Analyze NYC flight delays.   


Install the "nycflits13" package. The data comes from the US Bureau of Transportation Statistics. Using the data, complete the following tasks: 

1. Find all flights that had an arrival delay of >4 hours, return the first 5 row. (Note: `arr_delay` is in mins)
2. Find all flight names that flew from JFK to IAH, i.e. return only unique values of "flight" variable after filtering. Hint: `unique()` would help. 
3. Find how many flights were operated by UA. 
4. Find how many unique flights were operated by UA. 
5. Sort flights that have the most delayed flights. Show the first 5 row. 
6. Generate a scatter plot with x-axis `dist` and y-axis `delay`, where each dot is a unique flights and destination, `dist` is the average distance of each destination `dest`, and `delay` is the average delay time `arr_delay`, with the size of `dot` equals to the count of delay records. 

```{r}
library(nycflights13)
head(flights)
```

\clearpage

# Part 2: LaTeX.

1. Finish the Markdown tutorial: https://www.markdowntutorial.com/
2. (Tossing for a head, C&B Example 1.5.4) Suppose we do an experiment that consists of tossing a coin until a head appears. Let $p=$ probability of a    head on any given toss, and define a random variable $X=$ number of tosses required to get a head. **Use Rmarkdown to type the the solution.**

  (i) What is $P(X = x)$?
  (ii) For any positive integer $x$, calculate $P(X \leq x)$. 
  (iii) Calculate the cdf $F_{X}(x)$. 
  (iv) What is $\lim _{x \rightarrow \infty} F_{X}(x)$? 