This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCS_01.Rmd
52 lines (44 loc) · 2.14 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
51
52
---
title: Your first script
week: 1
subtitle: Write a script that reads in data, calculates a statistic, and makes a plot.
type: Case Study
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)
tasks:
- Create a new R script in RStudio (File->New File->R Script)
- Save this file somewhere you will find it later
- In your new script, load the iris dataset with `data(iris)`
- 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`
- Plot the distribution of the `Petal.Length` column as a histogram (`?hist`)
- Save the script
- Click 'Source' in RStudio to run your script 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")
```
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
```{r tasks,results='asis',echo=F}
md_bullet(rmarkdown::metadata$tasks)
```