This repository has been archived by the owner on Jan 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
CS_01.Rmd
50 lines (43 loc) · 1.91 KB
/
CS_01.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
47
48
49
50
---
title: Create a simple, functioning script
week: 1
subtitle: Write a script that reads in data, calculates a statistic, and makes a plot.
type: Case Study
reading:
- R4DS [Chapter 1](http://r4ds.had.co.nz/introduction.html)
- R4DS [Chapter 2](http://r4ds.had.co.nz/explore-intro.html)
- 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)
tasks:
- Create a new R script in RStudio
- Load the iris dataset with `data(iris)`
- Calculate the mean of the `Petal.Length` field
- Plot the distribution of the `Petal.Length` column as a histogram
- Save the script
- Click 'Source' in RStudio to run it from beginning to end
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
library(kableExtra)
source("functions.R")
```
# Reading
```{r reading,results='asis',echo=F}
md_bullet(rmarkdown::metadata$reading)
```
# Background
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.
It looks like this:
```{r, echo=F}
data(iris)
kable(iris) %>%
kable_styling() %>%
scroll_box(width = "100%", height = "200px")
```
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
```{r tasks,results='asis',echo=F}
md_bullet(rmarkdown::metadata$tasks)
```