Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
tidyverse tutorial 2
Search
kur0cky
September 27, 2019
Programming
1
57
tidyverse tutorial 2
tidyverse 超入門 2
講義用資料
kur0cky
September 27, 2019
Tweet
Share
More Decks by kur0cky
See All by kur0cky
The bootstrapping method for everyone
kur0cky
3
940
motemote-data-science-2
kur0cky
2
620
音楽理論と方向統計学の初歩/introduction of circular statistics and musicology
kur0cky
4
1.8k
NLP introduction in R 1
kur0cky
0
76
tidyverse tutorial 1
kur0cky
1
67
rating_introduction
kur0cky
1
840
motemote data science 1
kur0cky
1
530
Other Decks in Programming
See All in Programming
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
3
280
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
Zoneless Testing
rainerhahnekamp
0
120
Spatial Rendering for Apple Vision Pro
warrenm
0
110
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
useSyncExternalStoreを使いまくる
ssssota
6
1.1k
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
42 best practices for Symfony, a decade later
tucksaun
1
180
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Being A Developer After 40
akosma
87
590k
Code Review Best Practice
trishagee
65
17k
Docker and Python
trallard
42
3.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Six Lessons from altMBA
skipperchong
27
3.5k
Documentation Writing (for coders)
carmenintech
66
4.5k
The Cost Of JavaScript in 2023
addyosmani
45
7k
Rails Girls Zürich Keynote
gr2m
94
13k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Transcript
σʔλղੳͱલॲཧᶘ .ࠇ༟ୋ !FEUVTBDKQ
࣍ 3FWJFX&YFSDJTF +PJO 5JEZ%BUB !2
ຊ༻͢Δσʔλ TUBSXBST w ελʔΥʔζͷొਓʹؔ͢Δσʔλ IUUQTXBQJDP qJHIUT w ʹ-(" +',
&83Λग़ൃͨͯ͢͠ͷϑϥΠτͷఆࠁσʔλ XFBUIFS w -(" +', &83ͷఱީ෩ͷใ ࣌ؒ͝ͱ BJSMJOFT w ߤۭձࣾͷςʔϒϧ !3
3FWJFX&YFSDJTF
%BUB'SBNFͷجຊૢ࡞ EQMZS w ม ྻ ͷநग़ w ؍ଌ ߦ ͷநग़
w ؍ଌ ߦ ͷฒͼସ͑ w ৽ͨͳม ྻ ͷ࡞ w ूܭ w άϧʔϓԽ !5 • select() • filter() • arrange() • mutate() • summarise() • group_by()
͍ํ w ୈҾʹσʔλϑϨʔϜΛ༩͑Δ w ୈҾҎ߱Ͱྻ໊ΛΫΦʔςʔγϣϯແ͠Ͱ༩͑Δ w Γ৽ͨͳσʔλϑϨʔϜ %>%ͱ߹ΘͤͯരσʔλϋϯυϦϯάʂʂ !6
ԋश qJHIUTσʔλʹؔͯ͠ɺҎԼͷʹ͑Α ඈߦڑ͕࠷Ͱ͋Δศͷग़ൃͱతͲ͔͜ ౸ண࣌ࠁͷΕ͕ݦஶͳߤۭձࣾͲ͔͜ ग़ൃ࣌ࠁͱ౸ண࣌ࠁͷΕ͕ݦஶͳߤۭձࣾͲ͔͜ Կ࣌ൃͷඈߦػ͕࠷ଟ͍͔
ߤۭձࣾͷൟظ͍͔ͭ શͯͷߦͰdep_time - sched_dep_time = dep_delayͱͳ͍ͬͯΔ͜ͱΛ֬ೝ ͤΑ !7 # ύοέʔδ͔ΒಡΈࠐΉ library(nycflights13) data(flights)
+PJO
+PJO ͭͷςʔϒϧΛ LFZΛͱʹ݁߹͢Δૢ࡞ w ʮֶੜͷݸਓใςʔϒϧʯ w ʮतۀͷใςʔϒϧʯ w ʮཤमɾςʔϒϧʯ LFZ
w ʮֶੜʯ ʮʯɿLFZֶ੶൪߸ w ʮतۀʯ ʮཤमʯɿLFZतۀ*% !9 ʮਓɾतۀɾͷςʔϒϧʯ
+PJOͷछྨ w YͱZΛ+PJO͍ͨ͠ w ͬͱ୯७ͳͷ *OOFSKPJO w ॏෳ͢ΔLFZ͚ͩ͢ !10 ग़యɿIUUQTSETIBEDPO[
w -FGUKPJO w YͷLFZΛશͯ͢ w 3JHIUKPJO w ZͷLFZΛશͯ͢ w 'VMMKPJO
w ྆ํͷLFZΛશͯ͢ !11 ग़యɿIUUQTSETIBEDPO[
**_join()ͷ͍ํ inner_join(band_members, band_instruments, by = “name”) left_join(band_members, band_instruments2, by =
c(“name” = “artist”)) !12 > band_members name band 1 Mick Stones 2 John Beatles 3 Paul Beatles > band_instruments name plays 1 John guitar 2 Paul bass 3 Keith guitar > band_instruments2 artist plays 1 John guitar 2 Paul bass 3 Keith guitar
࿅श inner_join(), left_join(), right_join(), full_join() ͦΕͧΕͷग़ྗ݁ՌΛ༧͠ ࣮ࡍʹಈ͔ͯ֬͠ೝͤΑ qJHIUTσʔλͱBJSMJOFTσʔλΛDBSSJFSྻͰ݁߹ͤΑ
qJHIUTσʔλͱXFBUIFSσʔλΛPSJHJO ZFBS NPOUI EBZ IPVS ྻͰ݁߹ͤΑ !13
5JEZ%BUB
UJEZEBUB ͖ͪΜͱͨ͠σʔλ ఆٛʢग़యɿIUUQTSETIBEDPO[ʣ w ҰͭͷྻʹҰͭͷม BUPNJDWFDUPS w ҰͭͷߦʹҰͭͷ؍ଌ w
ҰͭͷηϧʹҰͭͷ w ݸʑͷ؍ଌશͯಉ͡ܗΛ͍ͯ͠Δ σʔλϑϨʔϜ্هΛຬͨ͢Α͏ʹ࡞Ζ͏ ˞ߦ໊ʢSPXOBNFTʣΘͣʹJOEFYJEͷྻΛ࡞Ζ͏ !15
NFTTZEBUB w Α͘ݟΔܗ w ਓؒʹΘ͔Γ͍͢ ʮԣ࣋ͪܗʯ w ҰͭͷྻʹҰͭͷม˚ w ҰͭͷߦʹҰͭͷ؍ଌ✖
w ҰͭͷηϧʹҰͭͷ̋ !16 12࣌ 15࣌ 17࣌ ౦ژ ‗ ‘ ‘ ໊ݹ ‗ ‗ ‘ େࡕ ‘ ‘ ‘ ྻ໊ ߦ໊
NFTTZEBUB w Α͘ݟΔܗ w ਓؒʹΘ͔Γ͍͢ ʮԣ࣋ͪܗʯ w ҰͭͷྻʹҰͭͷม˚ w ҰͭͷߦʹҰͭͷ؍ଌ✖
w ҰͭͷηϧʹҰͭͷ̋ !17 12࣌ 15࣌ 17࣌ ౦ژ ‗ ‘ ‘ ໊ݹ ‗ ‗ ‘ େࡕ ‘ ‘ ‘ ࣌ࠁ ఱؾ
UJEZEBUB w ղੳͰѻ͍͍͢ w ׳Εͳ͍͏ͪݟʹ͍͘ʁ ʮॎ࣋ͪܗʯ w ҰͭͷྻʹҰͭͷม̋ w ҰͭͷߦʹҰͭͷ؍ଌ̋
w ҰͭͷηϧʹҰͭͷ̋ !18 ࣌ࠁ ఱؾ ౦ژ ࣌ ‗ ໊ݹ ࣌ ‗ େࡕ ࣌ ‘ ౦ژ ࣌ ‘ ໊ݹ ࣌ ‗ େࡕ ࣌ ‘
NFTTZUJEZ !19 ྻ໊ʹͳͬͯ͠·͍ͬͯͨม໊ Λ ৽͍͠ZFBSͱ͍͏มʹ͢Δ
UJEZNFTTZ !20
3Ͱͷॎԣม !21 ॎ࣋ͪ ԣ࣋ͪ spread() gather() gather(df, key = “ྻ໊ʹདྷ͍ͯͨมΛ֨ೲ͢Δ৽ͨͳม໊”,
value = “ෳͷྻʹ·͕͍ͨͬͯͨมΛ·ͱΊΔ৽ͨͳม໊”, - มʹߟྀ͠ͳ͍ྻ໊) spread(df, key, value, fill = ͛ͨͱ͖ܽଌʹͳΔͱ͜ΖΛຒΊ͍ͨ)
࿅श ҎԼͷίʔυͰTUPDLT ٖࣅతͳऩӹσʔλ Λ࡞Γ ॎʹͤΑ stocks <- data.frame(
time = as.Date('2009-01-01') + 0:9, X = rnorm(10, 0, 1), Y = rnorm(10, 0, 2), Z = rnorm(10, 0, 4) ) ͱʹͤ !22
࣍ճ·Ͱͷ՝
՝ 1. ࠷ؾԹ͕ߴ͍தग़ൃͨ͠ศΛѲͤΑ 2. ଌఆ͞Εͨσʔλͷ͏ͪɺϘʔΠϯάࣾͷඈߦػԿճඈΜͰ͍Δ͔ 3. ඈߦػʹ࠾༻͞Ε͍ͯΔΤϯδϯͷछྨ͝ͱʹɺ1ճ͋ͨΓͷฏۉඈ ߦڑΛࢉग़ͤΑ 4. ڑ
or ڑʹಛԽ͍ͯ͠Δߤۭձࣾ͋Δ͔ɻ͋ΔͳΒɺஅ ཧ༝ड़Αɻ 5. ౦ʹ͔ͬͯඈͿศͱʹ͔ͬͯඈͿศͷͲͪΒ͕ଟ͍͔ (ඈߦػ తʹ͔ͬͯਐ͢Δͷͱ͢Δ) 6. ग़ൃ࣌ͷ࣪ͱɺग़ൃͷԆʹ૬ؔ͋Δ͔ !24
Α͋͘Δ࣭ w σʔλαΠΤϯεͷԿָ͕͍͠ʁ w σʔλ͔ΒݟΛಘΔ ͱ͍͏खଓ͖͕ԿΑΓָ͍͠ ࢲݟ w Ծઆɾݕূ͕ΩϨΠʹܾ·ͬͨͱ͖͕ؾ͍͍࣋ͪ
w ੜͷ͏ͪԿΛͨ͠Βྑ͍ʁ w جૅ ౷ܭֶ ࠷దԽ ઢܗ FUD ΛΩϟονΞοϓ͢Δ࣌ؒࠓޙͳ͘ͳͬͯ ͍͘ w ڵຯͷ͋Δσʔλ ڝഅ εϙʔπ FUD Λରʹ ੳΛֶΜͰ͍͘ͷྑ͍͔ ָ͠Ήͷ͕Ұ൪ w 3͕͍͠ w ؆୯ͦ͞͠͏ͳࢀߟॻΛݟͯΈΔͷ˕ !25