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
930
motemote-data-science-2
kur0cky
2
610
音楽理論と方向統計学の初歩/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
520
Other Decks in Programming
See All in Programming
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
150
React への依存を最小にするフロントエンド設計
takonda
6
1.4k
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
距離関数を極める! / SESSIONS 2024
gam0022
0
290
CSC509 Lecture 12
javiergs
PRO
0
160
cmp.Or に感動した
otakakot
3
210
subpath importsで始めるモック生活
10tera
0
320
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
CSC509 Lecture 09
javiergs
PRO
0
140
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
3
1.2k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1k
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Speed Design
sergeychernyshev
25
620
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
A Tale of Four Properties
chriscoyier
156
23k
Being A Developer After 40
akosma
87
590k
Embracing the Ebb and Flow
colly
84
4.5k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Adopting Sorbet at Scale
ufuk
73
9.1k
Designing Experiences People Love
moore
138
23k
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