This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
46 lines (34 loc) · 1.99 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
title: Case Study 1
week: 1
subtitle: Write a script that reads in data, calculates a statistic, and makes a plot.
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
library(kableExtra)
library(tidyverse)
```
# Background Reading
- Datacamp's [_How to Make a Histogram with Basic R_](https://www.datacamp.com/community/tutorials/make-histogram-basic-r)
- Datacamp's [_How to Make a Histogram with ggplot_](https://www.datacamp.com/community/tutorials/make-histogram-ggplot2)
# Introduction
You are working on a new project and your colleague has asked you to calculate the mean Petal Length in the dataset she collected in the field.
The dataset looks like this:
```{r, echo=F}
data(iris)
write_csv(iris, "iris.csv")
kable(head(iris))
```
To work with only one column in the `iris` dataset, try typing `iris$Sepal.Length`. What does the `$` do?
For the histogram, you can either use the basic `hist()` function (easier but less powerful) or try to use the `geom_hist()` function in ggplot (more complicated but much more powerful). See the reading list for hints on these two functions.
When you complete this task, you will have done some 'reproducible research' resulting in a script that calculates a statistic and makes a graph. In future lessons we'll cover how to save the graphic to your hardrive (if you are curious, check out the examples in `?png`)
# Tasks
- Open the `CS01.R` file in this assignment
- load the tidyverse package with `load(tidyverse)`
- In your new script, create a new object called `iris` by reading in the sample dataset with `read_csv("iris.csv")`
- Read the help file for the function that calculates the mean (you can run `?mean` or use the GUI).
- Calculate the mean of the `Petal.Length` field and save it as an object named `petal_length_mean`
- Click 'source' in RStudio to run your script from beginning to end
- run `test_dir("tests")` to see if your script passes all tests for this assignment