-
Notifications
You must be signed in to change notification settings - Fork 10
/
ch2_exercise.html
178 lines (135 loc) · 9.52 KB
/
ch2_exercise.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
<!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" />
<meta name="author" content="Yao-Jen Kuo" />
<meta name="date" content="2016-11-29" />
<title>單一變數與函數 - 隨堂練習</title>
<script src="ch2_exercise_files/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="ch2_exercise_files/bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="ch2_exercise_files/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="ch2_exercise_files/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="ch2_exercise_files/bootstrap-3.3.5/shim/respond.min.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<link rel="stylesheet"
href="ch2_exercise_files/highlight/default.css"
type="text/css" />
<script src="ch2_exercise_files/highlight/highlight.js"></script>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs && document.readyState && document.readyState === "complete") {
window.setTimeout(function() {
hljs.initHighlighting();
}, 0);
}
</script>
<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>
</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;
}
button.code-folding-btn:focus {
outline: none;
}
</style>
<div class="container-fluid main-container">
<!-- tabsets -->
<script src="ch2_exercise_files/navigation-1.1/tabsets.js"></script>
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
</script>
<!-- code folding -->
<div class="fluid-row" id="header">
<h1 class="title toc-ignore">單一變數與函數 - 隨堂練習</h1>
<h4 class="author"><em>Yao-Jen Kuo</em></h4>
<h4 class="date"><em>2016-11-29</em></h4>
</div>
<script src="https://cdn.datacamp.com/datacamp-light-latest.min.js"></script>
<div class="section level2">
<h2>換算公里與英里</h2>
<p>Tony 不知道全程馬拉松 42.195 公里換算成英里是多少?請用 R 語言的命令列當作計算機來幫助他。</p>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiIjIDEga20gZXF1YWxzIHRvIDAuNjIxMzcxMTkyIG1pbGVzXG5rbV90b19taWxlIDwtIF9fX1xuXG4jIFByaW50IGttX3RvX21pbGUgaW4gdGhlIGNvbnNvbGVcblxuXG4jIFRoZSBkaXN0YW5jZSBvZiBmdWxsIG1hcmF0aG9uIG1lYXN1cmVkIGluIGttXG5mdWxsX21hcmF0aG9uX2ttIDwtIDQyLjE5NVxuXG4jIFRoZSBkaXN0YW5jZSBvZiBmdWxsIG1hcmF0aG9uIG1lYXN1cmVkIGluIG1pbGVcbmZ1bGxfbWFyYXRob25fbWlsZSA8LSBfX19cbiAgXG4jIFByaW50IG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GZ1bGxfbWFyYXRob25fbWlsZWAuXCIpXG5zdWNjZXNzX21zZyhcIlRoYW5rIHlvdSBzbyBtdWNoLCBub3cgVG9ueSBrbm93cyB0aGF0IHRoZSBkaXN0YW5jZSBvZiBhIGZ1bGwgbWFyYXRob24gY291cnNlIGlzIDI2LjIgbWlsZXMhXCIpIn0=
</div>
</div>
<div class="section level2">
<h2>建立不同類型的變數</h2>
<p>在這個練習中熟練建立基本類型的變數:</p>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJzYW1wbGUiOiIjIENyZWF0ZSBhIG51bWVyaWMgdmFyaWFibGUgbXlfbnVtIGVxdWFscyB0byA4XG5teV9udW0gPC0gX19fXG5cbiMgQ3JlYXRlIGEgaW50ZWdlciB2YXJpYWJsZSBteV9pbnQgZXF1YWxzIHRvIDdMXG5teV9pbnQgPC0gX19fXG5cbiMgQ3JlYXRlIGEgbG9naWNhbCB2YXJpYWJsZSBteV9sb2dpIGVxdWFscyB0byBUUlVFXG5teV9sb2dpIDwtIF9fX1xuXG4jIENyZWF0ZSBhIGNoYXJhY3RlciB2YXJpYWJsZSBteV9jaGFyIGVxdWFscyB0byBcIkxlYXJuIFIgdGhlIGVhc3kgd2F5IVwiXG5teV9jaGFyIDwtIF9fX1xuICBcbiMgVXNlIGZ1bmN0aW9uOiBscygpIHRvIGxpc3QgYWxsIHRoZSB2YXJpYWJsZXMgd2UganVzdCBjcmVhdGVkXG5cblxuIyBVc2UgZnVuY3Rpb246IGNsYXNzKCkgdG8gY2hlY2sgdGhlIHZhcmlhYmxlIHR5cGVzIHJlc3BlY3RpdmVseVxuY2xhc3MoX19fKVxuY2xhc3MoX19fKVxuY2xhc3MoX19fKVxuY2xhc3MoX19fKSIsInNvbHV0aW9uIjoiIyBDcmVhdGUgYSBudW1lcmljIHZhcmlhYmxlIG15X251bSBlcXVhbHMgdG8gOFxubXlfbnVtIDwtIDhcblxuIyBDcmVhdGUgYSBpbnRlZ2V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BhbGwgdGhlIHZhcmlhYmxlcy5cIilcbm1zZyA8LSBcIkhhdmUgeW91IGNhbGxlZCBjbGFzcygpIG9uIGFsbCB0aGUgdmFyaWFibGVzIHlvdSBqdXN0IGNyZWF0ZWQ/XCJcbnRlc3Rfb3V0cHV0X2NvbnRhaW5zKFwiY2xhc3MobXlfbnVtKVwiLCBpbmNvcnJlY3RfbXNnID0gbXNnKVxudGVzdF9vdXRwdXRfY29udGFpbnMoXCJjbGFzcyhteV9pbnQpXCIsIGluY29ycmVjdF9tc2cgPSBtc2cpXG50ZXN0X291dHB1dF9jb250YWlucyhcImNsYXNzKG15X2xvZ2kpXCIsIGluY29ycmVjdF9tc2cgPSBtc2cpXG50ZXN0X291dHB1dF9jb250YWlucyhcImNsYXNzKG15X2NoYXIpXCIsIGluY29ycmVjdF9tc2cgPSBtc2cpIn0=
</div>
</div>
<div class="section level2">
<h2>運算並觀察類型</h2>
<p>把上一個練習所建立的變數拿來運用:</p>
<div data-datacamp-exercise="" data-height="300" data-encoded="true">
eyJsYW5ndWFnZSI6InIiLCJwcmVfZXhlcmNpc2VfY29kZSI6IiMgQ3JlYXRlIHZhcmlhYmxlcyBmcm9tIHRoZSBsYXN0IGV4ZXJjaXNlXG5teV9udW0gPC0gOFxubXlfaW50IDwtIDdMXG5teV9sb2dpIDwtIFRSVUVcbm15X2NoYXIgPC0gXCJMZWFybiBSIHRoZSBlYXN5IHdheSFcIiIsInNhbXBsZSI6IiMgQWRkIG15X251bSBhbmQgbXlfaW50XG5cblxuIyBVc2UgY2xhc3MoKSB0byBjaGVjayB0aGUgcmVzdWx0IGFib3ZlXG5cblxuIyBBZGQgbXlfaW50IGFuZCBteV9sb2dpXG5cblxuIyBVc2UgY2xhc3MoKSB0byBjaGVjayB0aGUgcmVzdWx0IGFib3ZlXG5cblxuIyBSZS1hc3NpZ24gbXlfbG9naSB3aXRoIEZBTFNFXG5cblxuIyBBZGQgbXlfbnVtIGFuZCBteV9sb2dpXG5cblxuIyBVc2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W91IGNhbGwgY2xhc3MoKSB0byBjaGVjayB0aGUgcmVzdWx0P1wiXG50ZXN0X291dHB1dF9jb250YWlucyhcImNsYXNzKG15X251bSArIG15X2ludClcIiwgaW5jb3JyZWN0X21zZyA9IG1zZylcbnRlc3Rfb3V0cHV0X2NvbnRhaW5zKFwiY2xhc3MobXlfaW50ICsgbXlfbG9naSlcIiwgaW5jb3JyZWN0X21zZyA9IG1zZylcbnRlc3Rfb3V0cHV0X2NvbnRhaW5zKFwiY2xhc3MobXlfbnVtICsgbXlfbG9naSlcIiwgaW5jb3JyZWN0X21zZyA9IG1zZylcbnN1Y2Nlc3NfbXNnKFwiV2VsbCBkb25lIVwiKSJ9
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
$(document).ready(function () {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>