-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathch-033-calculator.html
465 lines (422 loc) · 21.9 KB
/
ch-033-calculator.html
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<title>ch-033-calculator.utf8.md</title>
<script src="ch-033-calculator_files/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="ch-033-calculator_files/bootstrap-3.3.5/css/readable.min.css" rel="stylesheet" />
<script src="ch-033-calculator_files/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="ch-033-calculator_files/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="ch-033-calculator_files/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="ch-033-calculator_files/navigation-1.1/tabsets.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
{ content: attr(data-line-number);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ background-color: #f8f8f8; }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ef2929; } /* Alert */
code span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #c4a000; } /* Attribute */
code span.bn { color: #0000cf; } /* BaseN */
code span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4e9a06; } /* Char */
code span.cn { color: #000000; } /* Constant */
code span.co { color: #8f5902; font-style: italic; } /* Comment */
code span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
code span.dt { color: #204a87; } /* DataType */
code span.dv { color: #0000cf; } /* DecVal */
code span.er { color: #a40000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #0000cf; } /* Float */
code span.fu { color: #000000; } /* Function */
code span.im { } /* Import */
code span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #204a87; font-weight: bold; } /* Keyword */
code span.op { color: #ce5c00; font-weight: bold; } /* Operator */
code span.ot { color: #8f5902; } /* Other */
code span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
code span.sc { color: #000000; } /* SpecialChar */
code span.ss { color: #4e9a06; } /* SpecialString */
code span.st { color: #4e9a06; } /* String */
code span.va { color: #000000; } /* Variable */
code span.vs { color: #4e9a06; } /* VerbatimString */
code span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
<link rel="stylesheet" href="textbook.css" type="text/css" />
</head>
<body>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
</style>
<div class="container-fluid main-container">
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
</script>
<!-- code folding -->
<div class="fluid-row" id="header">
</div>
<script src="https://cdn.datacamp.com/datacamp-light-latest.min.js"></script>
<div id="r-an-overdesigned-calculator" class="section level1">
<h1><span class="header-section-number">1</span> R: An Overdesigned Calculator</h1>
<p><br></p>
<p><img src="https://i.giphy.com/media/3owzW5c1tPq63MPmWk/giphy.webp" width="100%" style="display: block; margin: auto;" /></p>
<p><br></p>
<div id="introduction" class="section level2">
<h2><span class="header-section-number">1.1</span> Introduction</h2>
<p>Chief among R’s many capabilities are basic mathematical operations, making it a severely overdesigned calculator. The only thing a TI-84 has on R is that you can’t play Super Mario Brothers with the latter - <em>yet</em> (package developers… if your listening…).</p>
<p><strong>So what?</strong></p>
<p>Arithmetic operations in R are key to transforming your data, whether calculating property code violations <em>per capita</em> or converting U.S. dollars to Indian rupees. In short, you use them to make new variables from existing ones. When we combine arithmetic with objects that store one or more values, we’re dangerously close to practicing algebra.</p>
<p><br> <br></p>
<div class="tip">
<h2 id="key-concepts"><span class="header-section-number">1.1</span> Key Concepts</h2>
<p>In this chapter, we’ll learn and practice basic arithmetic functions in R, assign calculations and their resulting values to objects, and use those objects in algebraic operations. Key concepts include:</p>
<ul>
<li>Arithmetic Operators</li>
<li>Operator Precedence</li>
<li>Assignment</li>
</ul>
<h2 id="key-takeaways"><span class="header-section-number">1.1</span> Key Takeaways</h2>
<p>Everything you need to know in a few bullet points:</p>
<ul>
<li>Arithmetic operators include: <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>^</code>, <code>( )</code></li>
<li>Calculations follow the <strong>order of operations</strong></li>
<li>Create <strong>objects</strong> with <strong>assignment</strong>:
<ul>
<li><code>x</code> stores the value <code>3</code> after calling <code>x <- 3</code></li>
</ul></li>
<li>Numeric bjects act like variables in algebra:
<ul>
<li><code>x + 2</code> equals <code>5</code></li>
</ul></li>
</ul>
<p><br> <br></p>
</div>
<p><br> <br></p>
</div>
<div id="arithmetic-operators" class="section level2">
<h2><span class="header-section-number">1.2</span> Arithmetic Operators</h2>
<blockquote>
<p>"What sort of free will is left when we come to tabulation and arithmetic? When it will all be a case of twice two makes four?</p>
<p>You don’t need free will to determine that twice two is four." (Dostoyevsky)</p>
</blockquote>
<p><br></p>
<p>You remember <a href="https://en.wikipedia.org/wiki/Arithmetic">arithmetic</a>, right? That peculiar field of mathematics in which people who admittedly “don’t math”, for whatever reason, actually use every day?</p>
<p><strong>Arithmetic operators</strong> in R work just like they did in primary school, including addition, subtraction, multiplication, division, and exponentiation:</p>
<ul>
<li><code>+</code> or <strong>addition</strong>, e.g. <code>2 + 2</code></li>
<li><code>-</code> or <strong>subtraction</strong>, e.g. <code>2 - 2</code></li>
<li><code>*</code> or <strong>multiplication</strong>, e.g. <code>2 * 2</code></li>
<li><code>/</code> or <strong>division</strong>, e.g. <code>2 / 2</code></li>
<li><code>^</code> or <strong>exponentiation</strong>, e.g. <code>2 ^ 2</code></li>
<li><code>( )</code> for <strong>order of operations</strong>, e.g. <code>((2 + 2) * 2)</code></li>
</ul>
<p><br></p>
<p>The following example has a number of operations. Run the code to see what happens:</p>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiI3ICsgMyAgICAgICAjIEFkZGl0aW9uXG5cbjggLSAxMiAgICAgICMgU3VidHJhY3Rpb25cblxuOSAqIDkgICAgICAgIyBNdWx0aXBsaWNhdGlvblxuXG4xMCAvIDMgICAgICAjIERpdmlzaW9uXG5cbjEwIF4gMyAgICAgICMgRXhwb25lbnRpYXRpb24ifQ==
</div>
<p><br></p>
<p>Eureka! Forget your mobile phone’s calculator app. Install R on it!</p>
<p>(Plus, you can browse Reddit during class, but it looks like you’re working).</p>
<p><br></p>
<div id="your-turn" class="section level3">
<h3><span class="header-section-number">1.2.1</span> Your Turn</h3>
<div class="quiz">
<p><strong>Instructions:</strong> Perform the following arithmetic operation in R.</p>
<p><strong>Tip:</strong> Numeric values in R <em>don’t use commas</em>.</p>
</div>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiIjIFJhaXNlIDUgdG8gdGhlIGZpZnRoIHBvd2VyXG5cbiMgU3VidHJhY3QgMzAgZnJvbSAxMDBcblxuIyBEaXZpZGUgMSwwMDAgYnkgMzAwIn0=
</div>
<p><br></p>
<div class="figure" style="text-align: center">
<img src="https://imgs.xkcd.com/comics/purity.png" alt="*Arithmetic operators are the most atomic functions in R programming.*" width="90%" />
<p class="caption">
<em>Arithmetic operators are the most atomic functions in R programming.</em>
</p>
</div>
<center>
<em>Source: <a href="https://xkcd.com/435/">XKCD</a></em>
</center>
<p><br> <br></p>
</div>
</div>
<div id="order-of-operations" class="section level2">
<h2><span class="header-section-number">1.3</span> Order of Operations</h2>
<p>Here’s another blast from the past: the <strong>operator precedence</strong>. At least, that’s what it’s called in programming languages. You probably remember it as the <strong>order of operations</strong>.</p>
<p>If you don’t recall the specific rules, perhaps you remember the mnemonic devices: <strong>PEMDAS</strong> or <strong>Please Excuse My Dear Aunt Sally</strong>. We are not sure know what Aunt Sally did, but we are pretty sure she deserves whatever punshinment she received.</p>
<p>PEMDAS reminds us <em>the order arithmetic operations are evaluated</em>, a.k.a. the <strong>order of operations</strong>:</p>
<ol style="list-style-type: decimal">
<li><strong>Parenthesis</strong>, or expressions inside <code>( )</code></li>
<li><strong>Exponents</strong>, or raising one value to the power of another with <code>^</code></li>
<li><strong>Multiplication</strong>, or multiplying values with <code>*</code></li>
<li><strong>Division</strong>, or dividing values with <code>/</code></li>
<li><strong>Addition</strong>, or adding values with <code>+</code></li>
<li><strong>Subtraction</strong>, or subtracting values with <code>-</code></li>
</ol>
<p>Arithmetic operations in R are also evaluated in the same order. Can you guess the results before evaluating the expressions? Press “Run” to execute the code and see the results:</p>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiIjIGVhc3kgb25lXG41ICsgMTAgLyA1ICAgIFxuXG4jIGhhcmRlclxuNSAtIDEwICsgNSBcbjUgKyAxMCAtIDUgIFxuXG4jIHNpbWlsYXJseVxuNSAqIDEwIC8gNSAgIFxuNSAvIDEwICogNSBcblxuIyBlYXNpZXJcbjMgKiAyIF4gMlxuXG4jIGhtbW1cbjIgKiAoMiArIDMpICogM1xuXG4jIGh1aD9cbiggMiArIDMgKSAvIDUgKiAyXG4oIDIgKyAzICkgKiA1IC8gMlxuKCAyICsgMyApIC8gMiAqIDUifQ==
</div>
<p><br></p>
<div class="tip">
<p>Note that R is indifferent to order of operations for addition vs subtraction, and multiplication vs division.</p>
<p>For cases where both occur the code is just executed from left to right.</p>
</div>
<div id="your-turn-1" class="section level3">
<h3><span class="header-section-number">1.3.1</span> Your Turn</h3>
<div class="quiz">
<p><strong>Instructions:</strong></p>
<p>The formula to calculate a monthly mortgage payment based upon the loan amount, annual interest rate, and loan term (in months) is calculated as follows:</p>
<p><span class="math display">\[
PAYMENT = \frac{principal \cdot \frac{interest \ rate}{12}}{1-(1+\frac{interest \ rate}{12})^{- \ months}}
\]</span></p>
<p>Let’s say we have a $100,000 loan at a 5% interest rate amortized over 360 months (30 years). The payments would be as follows:</p>
<p><span class="math display">\[
PAYMENT = \frac{ 100k \cdot \frac{0.05}{12}}{1-(1+\frac{0.05}{12})^{- \ 360}}
\]</span></p>
<p>Can you type the formula into R correctly? The payment should come to $536.82 a month.</p>
</div>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiIjIFR5cGUgeW91ciBmb3JtdWxhIGhlcmUifQ==
</div>
<p><br></p>
<div class="figure" style="text-align: center">
<img src="https://prairieworldcomicsblog.files.wordpress.com/2018/02/progelements7operators2.jpg?w=656" alt="*A different programming language, but you get the gist.*" width="90%" />
<p class="caption">
<em>A different programming language, but you get the gist.</em>
</p>
</div>
<center>
<em>Source: <a href="https://prairieworldcomicsblog.wordpress.com/2018/02/21/programming-elements-operators/">Prairie World Comics</a></em>
</center>
<p><br> <br></p>
</div>
</div>
</div>
<div id="assignment" class="section level1">
<h1><span class="header-section-number">2</span> Assignment</h1>
<blockquote>
<p>"The philosophical workers… have to fix and formalize some great existing body of valuations - that is to say…</p>
</blockquote>
<blockquote>
<p>…creations of value, which have become prevalent, and are for a time called ‘truths’…" (Nietzsche)</p>
</blockquote>
<p><br></p>
<p><strong>Objects</strong> are the meat and potatoes of R. They store information like datasets, function code, individual values, and even metadata, e.g. coefficents in linear models.</p>
<p><br></p>
<p><strong>But how do we create an object?</strong></p>
<p>We use <strong>assignment</strong> to create an object and store data in it. This requires the <strong>assignment operator</strong>, or the <code><-</code> arrow.</p>
<p>Assignment can be used to store external data that was imported into R, to save a statistic that we calculated, or remember data we type into R ourselves.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" data-line-number="1">x <-<span class="st"> </span><span class="kw">read.csv</span>( <span class="st">"FileName.csv"</span> ) </a>
<a class="sourceLine" id="cb1-2" data-line-number="2"></a>
<a class="sourceLine" id="cb1-3" data-line-number="3">x <-<span class="st"> </span><span class="kw">mean</span>( y )</a>
<a class="sourceLine" id="cb1-4" data-line-number="4"></a>
<a class="sourceLine" id="cb1-5" data-line-number="5">x <-<span class="st"> </span><span class="kw">c</span>(<span class="st">"Adam"</span>,<span class="st">"Susie"</span>,<span class="st">"Tony"</span>)</a></code></pre></div>
<p><br></p>
<p>Assign the values 3 and 4 to objects <code>x</code> and <code>y</code>, respectively. Note that typing an object’s name will report the object values.</p>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiJ4IDwtIDMgICAgICAgICMgQXNzaWduIDIwIHRvIFwieFwiXG5cbnkgPC0gNCAgICAgICAgIyBBc3NpZ24gNDgwIHRvIFwieVwiXG5cbnggICAgICAgICAgICAgIyBXaWxsIHRoaXMgcHJpbnQgXCJ4XCIgb3IgMyA/XG5cbnggKiB5ICAgICAgICAgIn0=
</div>
<p><br></p>
<p>Like algebra, <code>x</code> and <code>y</code> are used to <em>represent</em> numeric values.</p>
<p>Unlike algebra, we can <em>store many values</em> in objects, including other objects!</p>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiJ4IDwtIDIwICAgICAgIyBBc3NpZ24gMjAgdG8gXCJ4XCJcblxueSA8LSA0MCAgICAgICMgQXNzaWduIDQwIHRvIFwieVwiXG5cbnogPC0geCArIHkgICAjIEFzc2lnbiB0aGUgc3VtIG9mIFwieFwiIGFuZCBcInlcIiB0byBcInpcIlxuXG56ICAgICAgICAgICAgIyBQcmludCB6In0=
</div>
<p><br></p>
<p>What do you think the following will return?</p>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiJ4IDwtIDIwICAgICAgXG55IDwtIHggICAgXG54IDwtIDMwICBcblxueSAgICMgcHJpbnQgdGhlIHZhbHVlIHN0b3JlZCBieSB5In0=
</div>
<div class="tip">
<p><br></p>
<p><strong>Why does R use the <code><-</code> for assignment?</strong></p>
<p>Technically R allows you to use the equals <code>=</code> operator for <strong>assignment</strong> instead of using the arrow <code><-</code>.</p>
<p><strong>BUT YOU SHOULD NEVER DO IT!</strong>.</p>
<p>Assignment is important enough that the arrow helps keep your code easy to read.</p>
<p>Also, mind your spaces!</p>
<ul>
<li>x <- y is assignment</li>
<li>x < - y is less than negative y</li>
</ul>
<p><br></p>
</div>
<p><br></p>
<div id="your-turn-2" class="section level3">
<h3><span class="header-section-number">2.0.1</span> Your Turn</h3>
<div class="quiz">
<p>What will the following statements return?</p>
</div>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiJ4IDwtIDVcbnggPC0gMTBcbnhcblxueCA8LSA1XG54IDwgLSAxMCAgXG54XG5cbjUgPC0geFxuNVxuXG41IC0+IHggICAgXG54ICBcblxueCA9IDVcbnhcblxuNSA9IHggICAgXG54IFxuXG55IDwtIDEwXG54IDwtIHkgPC0gM1xueCJ9
</div>
<p><img src="https://media1.tenor.com/images/1c8f37ff011d490eb685ab86c7e22fc2/tenor.gif?itemid=5114756" /></p>
<center>
Jennifer Lawrence practicing assignment.
</center>
<p><br></p>
</div>
<div id="valid-object-names" class="section level2">
<h2><span class="header-section-number">2.1</span> Valid Object Names</h2>
<p>When creating new objects there are both rules and conventions for naming them.</p>
<p>The rules are fairly simple:</p>
<ol style="list-style-type: decimal">
<li>R is case sensitive, so <code>b</code> and <code>B</code> are different objects.</li>
<li>Object names can include letters, periods and underscores.</li>
<li>Object names can include numbers, but cannot begin with a number.</li>
</ol>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" data-line-number="1">x<span class="fl">.01</span> <-<span class="st"> </span><span class="dv">99</span> <span class="co"># good</span></a>
<a class="sourceLine" id="cb2-2" data-line-number="2">x_<span class="dv">01</span> <-<span class="st"> </span><span class="dv">99</span> <span class="co"># this works</span></a>
<a class="sourceLine" id="cb2-3" data-line-number="3"><span class="fl">01.</span>x <-<span class="st"> </span><span class="dv">99</span> <span class="co"># produces an error</span></a>
<a class="sourceLine" id="cb2-4" data-line-number="4"></a>
<a class="sourceLine" id="cb2-5" data-line-number="5">.x <-<span class="st"> </span><span class="dv">99</span> <span class="co"># this works</span></a>
<a class="sourceLine" id="cb2-6" data-line-number="6"><span class="fl">.1</span>x <-<span class="st"> </span><span class="dv">99</span> <span class="co"># this doesn't</span></a>
<a class="sourceLine" id="cb2-7" data-line-number="7">_x <-<span class="st"> </span><span class="dv">99</span> <span class="co"># oddly this doesn't</span></a></code></pre></div>
<p>In general it is good to name objects so they are easy to remember. You can combine words using one of three conventions:</p>
<ul>
<li>Camel Caps</li>
<li>Underscores</li>
<li>Periods</li>
</ul>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" data-line-number="1">myData <-<span class="st"> </span><span class="dv">99</span> <span class="co"># camel caps</span></a>
<a class="sourceLine" id="cb3-2" data-line-number="2">my_data <-<span class="st"> </span><span class="dv">99</span> <span class="co"># underscore</span></a>
<a class="sourceLine" id="cb3-3" data-line-number="3">my.data <-<span class="st"> </span><span class="dv">99</span> <span class="co"># periods</span></a></code></pre></div>
<p>Some people have strong views on these. You should find something that works for you and be consistent.</p>
<p><br></p>
<div class="figure" style="text-align: center">
<img src="https://imgs.xkcd.com/comics/forgot_algebra.png" alt="*You can't do this anymore, sadly.*" width="40%" />
<p class="caption">
<em>You can’t do this anymore, sadly.</em>
</p>
</div>
<center>
<em>Source: <a href="https://xkcd.com/1050/">XKCD</a></em>
</center>
<p><br> <br></p>
</div>
<div id="further-resources" class="section level2">
<h2><span class="header-section-number">2.2</span> Further Resources</h2>
<p>The following resources are helpful in learning more about arithmetic operators in R:</p>
<ul>
<li><a href="https://stat.ethz.ch/R-manual/R-devel/library/base/html/Arithmetic.html">“Arithmetic Operators”</a> (CRAN)</li>
<li><a href="http://rpubs.com/JamisonCrawford/operators">“Intro to R: Operators”</a> (Crawford, 2019)</li>
<li><a href="https://www.statmethods.net/management/operators.html">“Quick-R: Operators”</a> (Kabacoff, 2017)</li>
</ul>
<p><br> <br></p>
</div>
<div id="works-cited" class="section level2">
<h2><span class="header-section-number">2.3</span> Works Cited</h2>
<p>The Hangover (2009) The Hunger Games (2010)</p>
<p><br></p>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>