-
Notifications
You must be signed in to change notification settings - Fork 1
/
presentation.Rmd
159 lines (121 loc) · 2.67 KB
/
presentation.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
---
title: "R, y u do dis?"
author: Christoph Molnar
date: February 6, 2017
output: ioslides_presentation
widescreen: false
---
## R can be rewardingly easy to use
<img src="./img/ez.gif" width="600px" />
## R can be also a source of frustration
<img src="./img/code-not-working.gif" width="800px" />
## Let's do some simple calculations
```{r, results='hide'}
options(digits=22)
1.1 - 0.2
```
## Let's do some simple calculations
```{r}
options(digits=22)
1.1 - 0.2
```
## Let's do some simple calculations
<img src="./img/wat.jpg" width="800px" />
## Let's do some simple calculations
```{r}
options(digits=22)
1.1 - 0.2
```
Reason: Machine representation of float (numbers with decimal points)
## Usually differences are negligibly small
<img src="./img/small.jpg" width="800px" />
## Let's talk about any() and all()
```{r, results='hide'}
all(c())
any(c())
```
## Let's talk about any() and all()
```{r}
any(c())
```
## Let's talk about any() and all()
```{r}
all(c())
```
<img src="./img/arbitrary.jpg" width="500px" />
## Let's talk about any() and all()
Solution in the help file:
<img src="./img/all.png" width="800px" />
## Factors are super useful!
<img src="./img/gadget.jpg" width="800px" />
## Working with factors in R
```{r}
dat <- data.frame(measure = c('6','1', '1', '1', '2','10','4'))
as.numeric(dat$measure)
```
## Working with factors in R
```{r}
str(dat$measure)
```
## R is full of (implicit) coercion
<img src="./img/unexpected.gif" width="800px" />
## Implicit coercions is implicit!
```{r}
dat$measure
c(dat$measure, c(22, 1))
```
## Working with factors in R
<img src="./img/factor.png" width="800px" />
## require('bananas') vs library('bananas')
```{r, eval=FALSE}
require('bananas')
library('bananas')
```
## require('bananas') vs library('bananas')
```{r, error=TRUE}
require('bananas')
library('banana')
```
=> Use library in most cases
## require('bananas') vs library('bananas')
```{r, warning=FALSE, message=FALSE}
x <- require('bananas')
x
```
```{r, eval=FALSE}
if(!x){
install.packages('banana')
}
```
## require('bananas') vs library('bananas')
<img src="./img/banana.jpg" width="400px" />
## <- vs =
```{r}
x <- 1
x = 1
```
What's the difference?
## <- vs =
In practice same functionality.
```{r}
mean(new_var <- c(1,2))
new_var
```
## What about <<- ?
```{r}
var = 1
fun = function(x){var <<- x}
fun(2)
var
```
<img src="./img/fire.gif" width="300px" />
## Some advice
- R help is helpful, use it!
- Nice FAQ!
## Meta facts about the talk:
- Slides down with knitr+RMarkdown+ioslides
- Slides on Github: https://github.com/christophM/r-y-u-do-dis
- Time spent:
- 20% on content and practicing
- 80% on choosing the memes
# Thanks!