-
Notifications
You must be signed in to change notification settings - Fork 0
/
class1_solutions.Rmd
88 lines (55 loc) · 2.38 KB
/
class1_solutions.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
```{r global_options, include=FALSE}
library(knitr)
opts_chunk$set(fig.align="center", fig.height=4, fig.width=4)
```
##In-class worksheet 1
**Jan 19, 2016**
Much of the work in this class will be done via R Markdown documents. R Markdown documents are documents that combine text, R code, and R output, including figures. They are a great way to produce self-contained and documented statistical analyses.
In this first worksheet, you will learn how to do some basic markdown editing. After you have made a change to the document, press "Knit HTML" in R Studio and see what kind of a result you get.
Edit only below this line.
---------------------------------------------
## 1. Basic Markdown editing
Try out basic R Markdown features, as described [here.](http://rmarkdown.rstudio.com/authoring_basics.html) Write some text that is bold, and some that is in italics. Make a numbered list and a bulleted list. Make a nested list. Try the block-quote feature.
This text is **bold.**
This text is *in italics.*
A numbered list:
1. Item 1
2. Item 2
3. Item 3
A bulleted list:
- Item 1
- Item 2
- Item 3
A nested list:
1. Item 1
- Item 1.1. Note that 4 spaces are required for the nesting to work properly.
- Item 1.2
2. Item 2
Block quote:
> "If we knew what it was we were doing, it would not be called research, would it?" --- Albert Einstein
## 2. Embedding R code
R code embedded in R chunks will be executed and the output will be shown.
```{r}
x <- 5
y <- 7
z <- x * y
z
```
Play around with some basic R code. E.g., take the built-in data set `cars`, which lists speed and stopping distance for cars from the 1920. Plot speed vs. distance, and/or perform a correlation analysis. Then write a few sentences describing what you see.
Plot of speed vs. distance:
```{r}
plot(cars$dist, cars$speed)
```
Correlation analysis:
```{r}
cor.test(cars$dist, cars$speed)
```
There is a strong positive correlations. Cars with higher speed have longer stopping distances.
## 3. If this was easy
If this was easy, use Google to find out how to type-set mathematical formulas inside of R markdown.
Mathematical equations are described [here.](https://support.rstudio.com/hc/en-us/articles/200486328-Equations-in-R-Markdown)
For example, the geometric series:
$$
\sum_{k=0}^\infty r^k = \frac{1}{1-r}
$$
(Note that this only works if you are online, because a math rendering engine is downloaded on the fly.)