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
Contemporary Test Cases
maaretp
0
140
Click-free releases & the making of a CLI app
oheyadam
2
120
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
100
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
subpath importsで始めるモック生活
10tera
0
310
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
620
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
flutterkaigi_2024.pdf
kyoheig3
0
140
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Side Projects
sachag
452
42k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Bash Introduction
62gerente
608
210k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Happy Clients
brianwarren
98
6.7k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Music & Morning Musume
bryan
46
6.2k
Practical Orchestrator
shlominoach
186
10k
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