
---
output: 
  html_document:
  pdf_document: default
  word_document: default
title: "Assignment 14 - Optional: Writing a function - Loop"
---

***How to do it?***: 

- Open the Rmarkdown file of this assignment ([link](assignment14_optional.Rmd)) in Rstudio. 

- Right under each **question**, insert  a code chunk (you can use the hotkey `Ctrl + Alt + I` to add a code chunk) and code the solution for the question. 

- `Knit` the rmarkdown file (hotkey: `Ctrl + Alt + K`) to export an html.  

-  Publish the html file to your Githiub Page. 

***Submission***: Submit the link on Github of the assignment to Canvas

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

-------

1. Write the following function. Give examples to test your function.

- Input: a data frame

- Output: a data frame with all the missing of numeric variables replaced by the associated means.

Hint: [Similar function](https://bryantstats.github.io/math421/gganimate/18_writing_functions.html#28)

-------

2. Write the following function. Give examples to test your function.

- Input: a data frame

- Output: a data frame with all the missing of variables replaced by the associated means (for numeric variables) or modes (for non-numeric variables).

Hint: Use If-statement to combine the function in Problem 1 and the function in [this example](https://bryantstats.github.io/math421/gganimate/18_writing_functions.html#28)


-------

3. Write the following function. Give examples to test your function.

- Input: a data frame

- Output: Bar plots of all non-numeric variables

Hint: [Similar function](https://bryantstats.github.io/math421/gganimate/18_writing_functions.html#33)


-------

4. Write the following function. Give examples to test your function.

- Input: a data frame

- Output: all possible the bar plots of a non-numeric variable filled by a non-numeric variable.

Hint: [Similar function](https://bryantstats.github.io/math421/gganimate/18_writing_functions.html#40)

-------

5. Write the following function. Give examples to test your function.

- Input: a data frame

- Output: 

  - all possible the bar plots of a non-numeric variable filled by a non-numeric variable.
  
  - all possible the density plots of a numeric variable colored by a non-numeric variable
  
  - all possible the scatter plots.

Hint: Combine [this function](https://bryantstats.github.io/math421/gganimate/18_writing_functions.html#37), [this function](https://bryantstats.github.io/math421/gganimate/18_writing_functions.html#40), and the function in Question 4. One way to combine is creating a new function, `quick_plot`, and call these three functions within `quick_plot`. 

