install.packages("pacman"). Make sure of spelling and case.library(pacman)
p_load(char = c("tidyverse", 'broom', 'janitor', 'readxl'))
This installs and loads the meta-package tidyverse, and the packages broom, janitor and readxl into R.
p_load is a function within the pacman package. You can think of functions as recipes and packages as recipe books, if that helps.
The p_load function installs a package if you don’t have it on your computer, and then loads it. It just loads the package if you already have it installed. Note that you only need to install a package once on a computer.
Note that I’ve interchanged single and double quotes in the code snippet. Please feel free to use either single- or double-quotes or a mixture, as long as the quotes are properly paired by type.
We will continue with the airquality dataset we worked with in class. Learn more about this dataset by typing either help(airquality) or ?airquality at the console prompt.
In this homework you will create a report and a presentation on this dataset using RMarkdown. You will do this in the same RStudio project you created this week.
Your documents will incorporate the following 3 code snippets (in order) as R chunks and one piece of code inline. If I’m calling a package you do not have installed, use the p_load function above to install it.
library(tidyverse)
library(knitr)
avg_temp_by_month <- airquality %>%
group_by(Month) %>%
summarize(avgTemp = mean(Temp, na.rm=T))
kable(avg_temp_by_month)
ggplot(avg_temp_by_month, aes(x = Month, y = avgTemp)) +
geom_point() +
geom_line(color = 'blue') +
labs(y = 'Average Temperature (F)')
ggplot(airquality, aes(x = Wind, y = Ozone)) +
geom_point() +
geom_smooth(color = 'blue', se = FALSE)
max(airquality$Ozone, na.rm = T), which is the maximum recorded Ozone level. Incorporate into a sentence.
There is a Markdown Quick Reference available in under the Help menu to get you started.
Submit both the Rmds and the corresponding HTML files to Canvas. So you should be submitting 4 files for this part of the assignment. These should be named <your name>_HW1_report.Rmd, <your name>_HW1_report.html, <your name>_HW1_slides.Rmd, and <your name>_HW1_slides.html
The following section contains a templated R Markdown file that you can copy into a fresh R Markdown document in RStudio. You are expected to use the help system in R/RStudio as well as Google, if need be, to fill in the blanks below.
== checks for equality between two objects, and returns TRUE or FALSEis.character and is.numeric, you can check missing values with is.na, which gives a TRUE everytime it encounters a missing value in a data array, and FALSE otherwise. Internally in R, TRUE = 1.---
title: Homework 1, Part 2
author: _________ ___________
date: "BIOF 339"
---
```{r, echo = FALSE, eval=TRUE}
knitr::opts_chunk$set(message=FALSE, warning=FALSE)
```
## Descriptive statistics
We'll start with the `airquality` data set that is in-built in R.
1. The average temperature in June was `r ______(airquality$_____[airquality$Month==6], na.rm=TRUE)`.
2. Solar radiation data is missing on `r sum(is._____(airquality[,"Solar.R"]))` days, or in `r 100 * sum(is._____(airquality[,"Solar.R"]))/_______(airquality)` percent of all the days collected.
We can also visualize the missing data patterns in this data set.
```{r, echo = TRUE, eval=TRUE}
library(pacman)
p_load('naniar') # This is a package for missing data
vis_miss(______________) # see the documentation for vis_miss
```
Let's grab a more interesting data set. We will download and use the [Palmer Station penguins data set](doi:10.1371/journal.pone.0090081), which is in the form
of an R package on GitHub.
```{r, echo = TRUE, eval=TRUE}
library(pacman)
p_______('visdat') # Install and load visdat
p_install_gh('allisonhorst/palmerpenguins')
p_load('palmerpenguins')
vis_dat(penguins)
```
This part requires you to copy the template into a R Markdown file, called <your name>_HW1_template.Rmd. This should result in a HTML document called <your name>_HW1_template.html. Both files should be submitted. The total number of files to be submitted for the assignment in total is 6: 3 Rmd files and 3 html files.