-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert_monster_tabs_all_funs.Rmd
178 lines (102 loc) · 4.69 KB
/
insert_monster_tabs_all_funs.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
<ul class="nav nav-pills" id="myTab" role="tablist" style="margin-top: 18px;">
<li class="nav-item active">
<a class="nav-link" id="monsters-tab" data-toggle="tab" href="#monsters" role="tab" aria-controls="monsters" aria-selected="true"> `monsters` </a>
</li>
<li class="nav-item">
<a class="nav-link" id="filter3-tab" data-toggle="tab" href="#filter3" role="tab" aria-controls="filter3" aria-selected="false"> `filter`</a>
</li>
<li class="nav-item">
<a class="nav-link" id="select-tab" data-toggle="tab" href="#select" role="tab" aria-controls="select" aria-selected="false"> `select` </a>
</li>
<li class="nav-item">
<a class="nav-link" id="arrange-tab" data-toggle="tab" href="#arrange" role="tab" aria-controls="arrange" aria-selected="false"> `arrange`</a>
</li>
<li class="nav-item">
<a class="nav-link" id="mutate3-tab" data-toggle="tab" href="#mutate3" role="tab" aria-controls="mutate3" aria-selected="false"> `mutate`</a>
</li
<li class="nav-item">
<a class="nav-link" id="summarize-tab" data-toggle="tab" href="#summarize" role="tab" aria-controls="summarize" aria-selected="false"> `summarize`</a>
</li>
<li class="nav-item">
<a class="nav-link" id="group_by-tab" data-toggle="tab" href="#group_by" role="tab" aria-controls="group_by" aria-selected="false"> `group_by`</a>
</li>
<li class="nav-item">
<a class="nav-link" id="code-monsters-tab" data-toggle="tab" href="#code-monsters" role="tab" aria-controls="code-monsters" aria-selected="false"> `R code`</a>
</li>
</ul>
<div class="well tab-content monsters" id="myTabContent" style="background-color: white;">
<div class="tab-pane fade active in" id="monsters" role="tabpanel" aria-labelledby="monsters-tab">
![](../images/monsters/monster_data.png){style="width: 85%;"}
<br><br>
</div>
<div class="tab-pane fade" id="filter3" role="tabpanel" aria-labelledby="filter3-tab">
### Filter with a single condition / test {-}
![](../images/monsters/filter_monsters.png){style="width: 95%; margin-top: 12px;"}
<h3 style="margin-top: 20px;">Filter with multiple conditions / tests </h3>
![](../images/monsters/filter_monsters_multiple.png){style="width: 95%;"}
<br><br>
</div>
<div class="tab-pane fade" id="select" role="tabpanel" aria-labelledby="select-tab">
### Keep columns {-}
![](../images/monsters/select_monsters2.png){style="width: 98%; margin-top: 6px;"}
<h3 style="margin-top: 20px;">Drop columns </h3>
![](../images/monsters/select_monsters_drop2.png){style="width: 70%;"}
<br><br>
</div>
<div class="tab-pane fade" id="arrange" role="tabpanel" aria-labelledby="arrange-tab">
<h3 style="margin-top: 20px;"> Arrange from lowest to highest </h3>
![](../images/monsters/arrange_monsters.png){style="width: 98%; margin-top: 12px;"}
<h3 style="margin-top: 20px;"> Arrange from highest to lowest </h3>
![](../images/monsters/arrange_monsters_desc.png){style="width: 98%;"}
<br><br>
</div>
<div class="tab-pane fade" id="mutate3" role="tabpanel" aria-labelledby="mutate3-tab">
### Update existing column {-}
![](../images/monsters/mutate_monsters_update.png){style="width: 98%; margin-top: 12px;"}
<h3 style="margin-top: 20px;">Add a new column </h3>
![](../images/monsters/mutate_monsters_new.png){style="width: 98%;"}
<br><br>
</div>
<div class="tab-pane fade" id="summarize" role="tabpanel" aria-labelledby="summarize-tab">
![](../images/monsters_summarize.png){style="width: 98%;"}
<br><br>
</div>
<div class="tab-pane fade" id="group_by" role="tabpanel" aria-labelledby="group_by-tab">
![](../images/monsters_groupby.png){style="width: 92%; margin-top: 10px;"}
<br><br>
![](../images/monsters_groupby_step2.png){style="width: 94%; margin-top: 12px;"}
<br><br>
![](../images/monsters_groupby_step3.png){style="width: 94%; margin-top: 12px;"}
<br><br>
![](../images/monsters_groupby_result.png){style="width: 101%; margin-top: 12px;"}
</div></div>
<div class="tab-pane fade" id="code-monsters" role="tabpanel" aria-labelledby="code-monsters-tab">
```{r, eval=F, echo=T}
# Create monsters
monsters <- data.frame(id = 1:5,
color = c("pink", "green", "pink", "green", "green"),
age = c(8,2,7,3,1),
hat = c(T,T,F,T,F) )
# Filter ----
## Use a single condition/test
monsters %>% filter(color == "pink")
## Use multiple conditions/tests
monsters %>% filter(color == "pink", age > 7)
# Select ----
## Keep only 2 columns
monsters %>% select(id, age)
## Drop columns with a '-' in front
monsters %>% select(-hat)
# Arrange ----
## From low to high
monsters %>% arrange(age)
## Descend from high to low
monsters %>% arrange(desc(age))
# Mutate ----
## Update an existing column
monsters %>% mutate(age = age + 2)
## Create a new column
monsters %>% mutate(is_baby = age < 3)
```
</div>
</div>