forked from ntuaha/R_ETL_LAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2515 lines (2144 loc) · 72.6 KB
/
index.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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>ETL on R</title>
<meta charset="utf-8">
<meta name="description" content="ETL on R">
<meta name="author" content="Cheng Yu Lin (aha) and Jia Wei Chen (jiawei)">
<meta name="generator" content="slidify" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link rel="stylesheet" href="libraries/frameworks/io2012/css/default.css" media="all" >
<link rel="stylesheet" href="libraries/frameworks/io2012/css/phone.css"
media="only screen and (max-device-width: 480px)" >
<link rel="stylesheet" href="assets/css/docker_small.css" media="only screen and (max-device-width:950px)">
<link rel="stylesheet" href="assets/css/docker_large.css" media="only screen and (min-device-width:951px)">
<link rel="stylesheet" href="libraries/frameworks/io2012/css/slidify.css" >
<link rel="stylesheet" href="libraries/highlighters/highlight.js/css/tomorrow.css" />
<base target="_blank"> <!-- This amazingness opens all links in a new tab. --> <link rel=stylesheet href="libraries/widgets/quiz/css/demo.css"></link>
<link rel=stylesheet href="libraries/widgets/bootstrap/css/bootstrap.css"></link>
<link rel=stylesheet href="./assets/css/custom.css"></link>
<link rel=stylesheet href="./assets/css/ribbons.css"></link>
<!-- Grab CDN jQuery, fall back to local if offline -->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
<script>window.jQuery || document.write('<script src="libraries/widgets/quiz/js/jquery.js"><\/script>')</script>
<script data-main="libraries/frameworks/io2012/js/slides"
src="libraries/frameworks/io2012/js/require-1.0.8.min.js">
</script>
</head>
<body style="opacity: 0">
<slides class="layout-widescreen">
<!-- LOGO SLIDE -->
<slide class="title-slide segue nobackground">
<hgroup class="auto-fadein">
<h1>ETL on R</h1>
<h2></h2>
<p>Cheng Yu Lin (aha) and Jia Wei Chen (jiawei)<br/></p>
</hgroup>
<article></article>
<footer class = 'license'>
<a href='http://creativecommons.org/licenses/by-sa/3.0/'>
<img width = '80px' src = 'http://mirrors.creativecommons.org/presskit/buttons/88x31/png/by-sa.png'>
</a>
</footer>
</slide>
<!-- SLIDES -->
<slide class="" id="slide-1" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>故事的起源</h2>
</hgroup>
<article data-timings="">
<div style='float:left;width:30%' >
<ol>
<li><code>房價真的太高了嗎?</code></li>
</ol>
</div>
<div style='float:right;width:66%'>
<p><img src = './resources/figures/R_ETL_NEWS3.png' height="400px"></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-2" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>故事的起源</h2>
</hgroup>
<article data-timings="">
<div style='float:left;width:30%' >
<ol>
<li>房價真的太高了嗎?</li>
<li><code>大熊被抓了</code></li>
</ol>
</div>
<div style='float:right;width:66%'>
<p><img src = './resources/figures/R_ETL_NEWS_2.png' height="400px"></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-3" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>故事的起源</h2>
</hgroup>
<article data-timings="">
<div style='float:left;width:30%' >
<ol>
<li>房價真的太高了嗎?</li>
<li>大熊被抓了</li>
<li><code>台灣房市真的要崩盤了嗎?</code></li>
</ol>
</div>
<div style='float:right;width:66%'>
<p><img src = './resources/figures/R_ETL_NEWS_1.png' height="400px"></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-4">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
</hgroup>
<article class = 'flexbox vcenter'>
<p><q>在論述台灣房市之前,身為一個<code>資料科學家</code>,第一步是了解問題</q></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-5">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
</hgroup>
<article class = 'flexbox vcenter'>
<p><q>本次,我們的問題是<code>房價真的太高了嗎?</code></q></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-6" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<article data-timings="">
<p>還記得這個<code>新聞</code>吧? 就從這裡開始
<img src = './resources/figures/R_ETL_NEWS_1.png' height="400px"></img></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-7" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>資料在哪裡</h2>
</hgroup>
<article data-timings="">
<p>從上面<code>新聞</code>所述,所以我們想要:</p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-8" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>資料在哪裡</h2>
</hgroup>
<article data-timings="">
<p>從上面<code>新聞</code>所述,所以我們想要:</p>
<div style='float:left;width:48%;'>
<h3><code>你想知道什麼資料?</code></h3>
<ol>
<li>GDP</li>
<li>房貸餘額</li>
<li>股價</li>
<li>新聞</li>
<li>地價資訊</li>
</ol>
</div>
<div style='float:right;width:48%;'>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-9" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>資料在哪裡</h2>
</hgroup>
<article data-timings="">
<p>從上面<code>新聞</code>所述,所以我們想要:</p>
<div style='float:left;width:48%;'>
<h3><code>你想知道什麼資料?</code></h3>
<ol>
<li>GDP</li>
<li>房貸餘額</li>
<li>股價</li>
<li>新聞</li>
<li>地價資訊</li>
</ol>
</div>
<div style='float:right;width:48%;'>
<h3><code>可能的來源?</code></h3>
<ol>
<li>政府公開資料
<ul>
<li>主計處</li>
<li>央行</li>
</ul></li>
<li>新聞
<ul>
<li>紙本報紙</li>
<li>電視新聞</li>
<li>電子新聞</li>
</ul></li>
<li>股市
<ul>
<li>Yahoo Stock API</li>
</ul></li>
</ol>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-10">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
</hgroup>
<article class = 'flexbox vcenter'>
<p><q>即便知道資料在哪,可是資料還是如同<code>一盤散沙</code></q></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-11" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>看看Raw Data</h2>
</hgroup>
<article data-timings="">
<p><img src = './resources/figures/R_ETL_RAWDATA.png' height="350px"></img></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-12" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>我們ETL會用到的有</h2>
</hgroup>
<article data-timings="">
<ul>
<li><code>dplyr</code> 可用<code>類似SQL方法</code>操作data frome</li>
<li><code>xts</code> 處理<code>時間</code>格式好用的套件</li>
<li><code>gdata</code> 可以處理<code>Excel 2007</code>以上的文件</li>
<li><code>quantmod</code> 可以處理<code>股市</code>資料</li>
<li><code>stringr</code> <code>字串</code>相關處理</li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="quote" id="slide-13" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<article data-timings="">
<p><q>來上課的,有<code>福</code>了</q></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-14" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>DSC的One Piece</h2>
</hgroup>
<article data-timings="">
<ul>
<li><code>DSC2014Tutorial</code> R社群為了這次Tutorial製作的套件,所有的教材都在這了</li>
</ul>
<pre><code>deps <- available.packages("http://taiwanrusergroup.github.io/R/src/contrib")[1,"Imports"]
pkgs <- strsplit(gsub("\\s", "", deps), ",")[[1]]
for(i in seq_along(pkgs)) {
# You can change your favorite repository
if (require(pkgs[i], character.only = TRUE)) next
install.packages(pkgs[i], repo = "http://cran.csie.ntu.edu.tw")
}
install.packages('DSC2014Tutorial',
repo = 'http://taiwanrusergroup.github.io/R', type = 'source')
library(DSC2014Tutorial)
</code></pre>
<p>安裝之後, 輸入以下指令就可以打開投影片:</p>
<pre><code>slides("ETL")
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-15" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>解決資料散亂的方法 - <code>ETL</code></h2>
</hgroup>
<article data-timings="">
<p><img src = './resources/figures/R_ETL_ETL.png' height="350px"></img></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-16" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>ETL 的主要內容</h2>
</hgroup>
<article data-timings="">
<p><img src = './resources/figures/R_ETL_ETL_3.png' height="350px"></img></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-17" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>今日解決的問題流程 - <code>ETL</code></h2>
</hgroup>
<article data-timings="">
<p><img src = './resources/figures/R_ETL_ETL_2.png' height="350px"></img></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-18" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>今日課程的目標</h2>
</hgroup>
<article data-timings="">
<h3>學會<strong>extraction</strong>, <strong>cleaning</strong>, <strong>transformation</strong></h3>
<ul>
<li>用R整理<code>結構</code>化資料 <strong>STEP1 房貸餘額1</strong> , <strong>STEP2 GDP</strong></li>
<li>用R整理<code>非結構化</code>資料 <strong>STEP3新聞分析</strong></li>
</ul>
<h3>學會 <strong>load</strong></h3>
<ul>
<li>整併全部的資料 STEP4</li>
</ul>
<h3>邁向 <strong>其他有意思的主題</strong></h3>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="dark segue" id="slide-19" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>學習,實作,觀察 STEP1</h2>
</hgroup>
<article data-timings="">
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-20" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>ETL <code>第一步</code></h2>
</hgroup>
<article data-timings="">
<p><img src = './resources/figures/R_ETL_ETL_2.png' height="350px"></img></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-21" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>開始收集資料(房貸餘額)</h2>
</hgroup>
<article data-timings="">
<p>請連線到
<code>https://survey.banking.gov.tw/statis/stmain.jsp?sys=100&funid=r100</code></p>
<iframe src = 'https://survey.banking.gov.tw/statis/stmain.jsp?sys=100&funid=r100' height='400px'></iframe>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-22" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>開始收集資料</h2>
</hgroup>
<article data-timings="">
<h3>房貸餘額,直接下載現成的csv檔案</h3>
<ul>
<li>直接到<a href="https://raw.githubusercontent.com/ntuaha/TWFS/master/db/cl_info_other.csv">https://raw.githubusercontent.com/ntuaha/TWFS/master/db/cl_info_other.csv</a>下載檔案</li>
<li>應該會看見<code>cl_info_other.csv</code></li>
<li>讀入它!</li>
</ul>
<p>或是</p>
<pre><code class="r">library(DSC2014Tutorial)
ETL_file("cl_info_other.csv")
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-23" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>讀入資料 - read.table</h2>
</hgroup>
<article data-timings="">
<p>至少要記得的 <code>read.table</code></p>
<pre><code>Cl_info = read.table(file=ETL_file("cl_info_other.csv"),sep=",",stringsAsFactors=F,header=T)
</code></pre>
<ul>
<li>輸出形態為<code>Data Frame</code></li>
<li>file 就是指讀入的檔案路徑</li>
<li>sep 指的是欄位分割用的符號,通常csv檔案格式是透過<code>,</code>做分割</li>
<li>stringsAsFactors 預設是<code>True</code>, 會讓讀入的字串都用Factor形態儲存,那麼資料就會轉為整數儲存與額外的對照表</li>
<li>header 預設是<code>False</code>,表示第一行是不是表格標頭,作為輸出的dataframe欄位名的colnames</li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-24" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>看看讀入結果</h2>
</hgroup>
<article data-timings="">
<pre><code>View(Cl_info)
str(Cl_info)
</code></pre>
<p><img src = './resources/figures/R_ETL_EXP1.png' height="350px"></img></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="quote" id="slide-25" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<article data-timings="">
<p><q>直接讀入是否覺得怪怪的?</q></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-26" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>再看一次</h2>
</hgroup>
<article data-timings="">
<p><img src = './resources/figures/R_ETL_EXP1.png' height="350px"></img></p>
<ul>
<li><code>etl_dt</code> <code>data_dt</code> 是<code>文字</code>但應該是<code>時間</code></li>
<li><code>bank_code</code> 也是<code>文字</code>但應該是<code>factor</code></li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-27" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>Transformation - 資料處理</h2>
</hgroup>
<article data-timings="">
<h3>將資料讀入</h3>
<pre><code>library(DSC2014Tutorial)
library(dplyr)
Cl_info = read.table(file=ETL_file('cl_info_other.csv'),header=T,sep=",",stringsAsFactors=F)
Cl_info_part = mutate(Cl_info,data_dt = as.POSIXct(data_dt),
bank_code = as.factor(bank_code),etl_dt = as.POSIXct(etl_dt))
View(Cl_info_part)
str(Cl_info_part)
</code></pre>
<p><br/></p>
<ul class = "build incremental">
<li>到這裡已經完成第一次的資料<code>Extraction</code>與<code>Transformation</code>了!</li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="quote" id="slide-28" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<article data-timings="">
<p><q>看見資料了!但是剛剛處理過程中的<code>mutate</code>是什麼?</q></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="quote" id="slide-29" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<article data-timings="">
<p><q>看見資料了!但是剛剛處理過程中的<code>mutate</code>是什麼?</q></p>
<p><q> 在<code>R</code>中用來做<strong>資料清理</strong>與<strong>資料處理</strong>好用的套件<code>dplyr</code>其中之一的函式<q></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="quote" id="slide-30" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<article data-timings="">
<p><q> 接下來我們將介紹三個基本函式 </q></p>
<p><img src = './resources/figures/R_ETL_Fn1.png' height="350px"></img></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-31" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>練習-挑選<code>欄位</code>(1/2)</h2>
</hgroup>
<article data-timings="">
<h3>dplyr <code>select</code> 函式,用來<strong>挑選</strong><code>欄位</code></h3>
<div style='float:left;width:68%' >
<pre><code>Cl_demo1 = select(資料表,欄位1,欄位2,欄位3)
</code></pre>
<ul>
<li><code>第一個參數</code>為輸入的data frame</li>
<li><code>後續參數</code>為選取的欄位名稱</li>
</ul>
<p><br/></p>
<h3>給熟悉<code>SQL</code>的使用者</h3>
<pre><code>select data_dt,bank_nm,mortgage_bal from Cl_info;
</code></pre>
</div>
<div style='float:right;width:28%'>
<p><img src = './resources/figures/R_ETL_DPLYR_SELECT.png'></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-32" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>練習-挑選<code>欄位</code>(2/2)</h2>
</hgroup>
<article data-timings="">
<h3>dplyr <code>select</code> 函式,用來<strong>挑選</strong><code>欄位</code></h3>
<div style='float:left;width:68%' >
<pre><code>Cl_demo1 = select(Cl_info,data_dt,bank_nm,mortgage_bal)
</code></pre>
<ul>
<li><code>第一個參數</code>為輸入的data frame</li>
<li><code>後續參數</code>為選取的欄位名稱</li>
</ul>
<p><br/></p>
<h3>給熟悉<code>SQL</code>的使用者</h3>
<pre><code>select data_dt,bank_nm,mortgage_bal from Cl_info;
</code></pre>
</div>
<div style='float:right;width:28%'>
<p><img src = './resources/figures/R_ETL_DPLYR_SELECT.png'></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-33" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>練習-挑選<code>資料</code></h2>
</hgroup>
<article data-timings="">
<h3>dplyr <code>filter</code> 函式,用來<strong>保留</strong>要留下的<code>資料列</code></h3>
<div style='float:left;width:68%' >
<pre><code>Cl_demo2 = filter(Cl_info,mortgage_bal>1000000)
</code></pre>
<ul>
<li><code>第一個參數</code>為輸入的data frame</li>
<li><code>第二個參數</code>為邏輯運算式,可用data frame裡的欄位,當結果為<code>True</code>時,該筆資料列保留</li>
</ul>
<p><br/></p>
<h3>給熟悉<code>SQL</code>的使用者</h3>
<pre><code>select * from Cl_info where mortgage>1000000;
</code></pre>
</div>
<div style='float:right;width:28%'>
<p><img src = './resources/figures/R_ETL_DPLYR_FILTER.png'></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-34" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>練習-增加<code>特徵</code>欄位(1/2)</h2>
</hgroup>
<article data-timings="">
<h3>dplyr <code>mutate</code> 用來增加<strong>非彙總</strong>計算<code>欄位</code></h3>
<div style='float:left;width:68%' >
<pre><code>Cl_demo3 = mutate(資料表,新欄位名 = 運算式)
</code></pre>
<ul>
<li><code>第一個參數</code>為輸入的 data frame</li>
<li><code>第二參數</code>為計算式,也可以用來當做<strong>轉換資料形態</strong>,<strong>變更欄位為名稱</strong>使用</li>
</ul>
<ul class = "build incremental">
<li>例如: bank_code = as.numeric(bank_code)</li>
</ul>
<p><br/></p>
<h3>給熟悉<code>SQL</code>的使用者</h3>
<pre><code>select mortgage_bal/1000000 as mortage from Cl_info;
</code></pre>
</div>
<div style='float:right;width:28%'>
<p><img src = './resources/figures/R_ETL_DPLYR_MUTATE.png'></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-35" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>練習-增加<code>特徵</code>欄位(2/2)</h2>
</hgroup>
<article data-timings="">
<h3>dplyr <code>mutate</code> 用來增加<strong>非彙總</strong>計算<code>欄位</code></h3>
<div style='float:left;width:68%' >
<pre><code>Cl_demo3 = mutate(Cl_info,mortage = mortgage_bal/1000000)
</code></pre>
<ul>
<li><code>第一個參數</code>為輸入的 data frame</li>
<li><code>第二參數</code>為計算式,也可以用來當做<strong>轉換資料形態</strong>,<strong>變更欄位為名稱</strong>使用</li>
</ul>
<p><br/></p>
<h3>給熟悉<code>SQL</code>的使用者</h3>
<pre><code>select mmortgage_bal/1000000 as mortage from Cl_info;
</code></pre>
</div>
<div style='float:right;width:28%'>
<p><img src = './resources/figures/R_ETL_DPLYR_MUTATE.png'></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-36" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>練習-<code>排序</code>資料(1/2)</h2>
</hgroup>
<article data-timings="">
<h3>dplyr <code>arrange</code> 用來重新排序</h3>
<div style='float:left;width:68%' >
<pre><code>Cl_demo4 = arrange(資料表,欄位1,desc(欄位2)))
</code></pre>
<ul>
<li><code>第一個參數</code>為輸入的 data frame</li>
<li><code>後續參數</code>為排序用欄位,預設遞增,可以透過<code>desc()</code>變成遞減排序</li>
</ul>
<p><br/></p>
<h3>給熟悉<code>SQL</code>的使用者</h3>
<pre><code>select * from Cl_info order by mortage,data_dt desc ;
</code></pre>
</div>
<div style='float:right;width:28%'>
<p><img src = './resources/figures/R_ETL_DPLYR_ARRANGE.png'></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-37" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>練習-<code>排序</code>資料(2/2)</h2>
</hgroup>
<article data-timings="">
<h3>dplyr <code>arrange</code> 用來重新排序</h3>
<div style='float:left;width:68%' >
<pre><code>Cl_demo4 = arrange(Cl_info,mortgage_bal,desc(data_dt))
</code></pre>
<ul>
<li>輸出data frame</li>
<li><code>第一個參數</code>為輸入的 data frame</li>
<li><code>後續參數</code>為排序用欄位,預設遞增,可以透過<code>desc()</code>變成遞減排序</li>
</ul>
<p><br/></p>
<h3>給熟悉<code>SQL</code>的使用者</h3>
<pre><code>select * from Cl_info order by mortage,data_dt desc ;
</code></pre>
</div>
<div style='float:right;width:28%'>
<p><img src = './resources/figures/R_ETL_DPLYR_ARRANGE.png'></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-38" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>練習時間</h2>
</hgroup>
<article data-timings="">
<ol>
<li>請幫忙從Cl_info_part找出<code>data_dt</code>,<code>bank_nm</code>,<code>mortgage_bal</code></li>
<li>請幫忙從Cl_info_part挑選出<code>mortgage_bal</code>大於1千萬的銀行資料</li>
<li>請幫忙排序Cl_info_part出<code>mortgage_bal</code>由小到大,但資料時間<code>data_dt</code>從大到小</li>
<li>請執行下面程式碼,我們後續會利用<code>Cl_info_part2</code></li>
</ol>
<pre><code>Cl_info_part2 = mutate(Cl_info_part,time= as.POSIXct(data_dt))
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="dark segue" id="slide-39" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>學習,實作,觀察 STEP2</h2>
</hgroup>
<article data-timings="">
</article>
<!-- Presenter Notes -->
</slide>
<slide class="quote" id="slide-40" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<article data-timings="">
<p><q>讓我們來練習抓下一個資料<code>GDP</code></q></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-41" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>ETL <code>第二步</code></h2>
</hgroup>
<article data-timings="">
<p><img src = './resources/figures/R_ETL_ETL_2.png' height="350px"></img></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-42" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>開始收集資料(GDP)</h2>
</hgroup>
<article data-timings="">
<p>請連線到 <code>http://ebas1.ebas.gov.tw/pxweb/Dialog/NI.asp</code></p>
<iframe src = 'http://ebas1.ebas.gov.tw/pxweb/Dialog/NI.asp' height='400px'></iframe>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-43" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>開始收集資料(GDP)</h2>
</hgroup>
<article data-timings="">
<ol>
<li>GDP從直接下載<code>國民生產毛額之處分</code></li>
<li>季(1980之後)</li>
<li>選<strong>全部的日期</strong></li>
<li>選<strong>全部的計價方式</strong></li>
<li>項目選<strong>GDP</strong></li>
<li>總類選<strong>原始值</strong></li>
<li>按繼續後,選<strong>從螢幕顯示Excel檔</strong></li>
<li>開啟後,<strong>另存新檔成csv檔</strong></li>
<li>開回<code>RStudio</code> 開始處理資料</li>
</ol>
<p>或是<code>ETL_file("GDP.txt")</code></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-44">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
</hgroup>
<article class = 'flexbox vcenter'>
<p><q>練習讀入與創建一個<code>GDP</code>的 data frame</q></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="quote" id="slide-45" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<article data-timings="">
<p><q>答案</q></p>
<pre><code class="r">GDP = read.table(file=ETL_file("GDP.txt"),sep=",",stringsAsFactors=F,header=F)
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="quote" id="slide-46" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<article data-timings="">
<p><q>輸入<code>View(GDP)</code>觀察<code>GDP</code>會發現怎麼前後有很多列的資料是不要的</q>
<img src = './resources/figures/R_ETL_2.png' ></img></p>
<h3>好亂,我想<code>整理</code>好這個data frome</h3>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-47" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>資料清理</h2>
</hgroup>
<article data-timings="">
<div style='float:left;width:38%' >
<h3>要處理的標的物有</h3>
<ol>
<li>去除前後<code>不相干</code>的資料列</li>
<li>轉換欄位的格式
<ul>
<li>將單位轉換,從<code>百萬元變成元</code></li>
<li>將不應該出現的<code>,</code>去除</li>
</ul></li>
<li>抽離<code>年份</code>與<code>季</code></li>
</ol>
</div>
<div style='float:right;width:58%'>
<p><img src = './resources/figures/R_ETL_1.png' ></img></p>
</div>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-48" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>去除前後不相干的資料列</h2>
</hgroup>
<article data-timings="">
<pre><code>GDP_part = GDP[5:136,]
</code></pre>
<h3>別忘了改上欄位名稱</h3>
<pre><code>colnames(GDP_part) = c("time","GDP","GDP_yoy","GDP_2006","GDP_2006_yoy",
"GDP_minus","GDP_minus_yoy")
</code></pre>
<p><img src = './resources/figures/R_ETL_GDP_1.png' ></img></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-49" style="background:; background-repeat:no-repeat; background-position:center; ">
<img src="assets/img/Taiwan-R-logo.png" class="logo fit100" />
<hgroup>
<h2>去除rownames</h2>
</hgroup>
<article data-timings="">
<pre><code>rownames(GDP_part) = NULL
View(GDP_part)
</code></pre>
<p>另外一個簡單的例子</p>
<pre><code>iris
iris_part <- iris[4:6,]
rownames(iris_part) <- c('a','c','d')
View(iris_part)
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>