-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsession_01_speaker.Rmd
211 lines (146 loc) · 3.03 KB
/
session_01_speaker.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
---
title: Session 1 — Speaker Notes
date: "July 18, 2018"
---
## Introduction
Using [slides](slides/session_01_slides.html)
1. Meet and greet
- Group sharing
- Name/Role
- First computer
- Wildest dreams
- About me
1. Why R and the tidyverse?
- What is R, what is the tidyverse
- Pit of success
- GUIs vs code
- Code is text
- Sharing, reading, copy paste, manipulate
1. Joining the community
- Expectations
- Coding myth
- Meet the community
## Lay of the Land
Walk through open panes in plain RStudio
### Console
#### Calculator
```r
1 + 100
1 +
3 + 5 * 2
(3 + 5) * 2
(3 + (5 * (2 ^ 2))) # hard to read
3 + 5 * 2 ^ 2 # clear, if you remember the rules
3 + 5 * (2 ^ 2) # if you forget some rules, this might help
2/10000 # scientific notation
5e3
```
#### Advanced Calculator
```r
sin(1)
log(1)
```
#### Comparing Things
```r
1 == 1
1 != 2
1 < 2
4 <= 5
4 > 5 # FALSE
10 >= 1
FALSE == F
TRUE == T
```
### Environment
Demonstrate how objecst are stored in your environment
```r
x <- 1/40
log(x)
x <- round(x, 1)
y <- x
```
### Script
Scripts hold code, demonstrate how to enter in file and how to run from file.
#### Variable Names
- Numbers, letters, underscores, periods
- Can't start with number
- Can use spaces but not recommended
```r
name.with.dots <- 3
nameWithCamelHumps <- 2
name_with_underscores <- 1
```
#### History
Previously run commands show up in the history.
### More syntax
#### Vectors
```r
c(1, 2)
c(1, 2, 3, 4, 5)
1:5
c(1, 2, 3) * 2
x <- seq(1, 10, by = 2)
x * 2
mean(x)
```
#### Strings or character
```r
word1 <- "Core"
word2 <- 'Data' # " or '
word3 <- "Services"
c(word1, word2, word3)
cds <- paste(word1, word2, word3)
tolower(cds)
```
#### Vectors vs Lists
At this point, we've seen `integer`, `numeric`, `logical` and `character`.
```r
typeof(3.14)
typeof(1) #<< double
typeof(1L) #<< integer
typeof(TRUE)
typeof("apple")
```
Vectors can only have things of the same type
```r
c(2, 4, 6)
c(2, 4, 6L)
typeof(c(2, 4, 6L))
c(1L, "1")
c("a", TRUE)
```
Lists can have anything you want
```r
list("a", 1L, 3.14, 1:5, FALSE)
list("a", 1:5, c("a", 1:5))
list(1:5, c("a", "b", "c", "d", "e"))
```
### Data Frames
```r
data.frame(1:5, c("a", "b", "c", "d", "e"))
data.frame(x = 1:5, y = c("a", "b", "c", "d", "e"))
```
### Working directories
`getwd()` and `setwd()` set where your current session of R looks for files.
### RStudio Projects
- Organize your code and data together
- Treat input data as read-only inside a project
- Easy to switch "contexts"
- Restart from scratch often!
- Creating new projects
- Interactive vs Scripts
- create a project for this course
## Packages
- `install.packages()`
- `library()`
- `library(tidyverse)`
- `pkg::function()`
## Getting Help
- `?help` and `??help`
- tidyverse.org
- stackoverflow
## Intro data processing
Go back to the [session page](session_01.html#lets-process-some-data)
- tidyverse: readr and dplyr
- readr: read_csv
- dplyr: group_by, count, summarize, filter