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
77
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
テストコード書いてみませんか?
onopon
2
200
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
150
Zoneless Testing
rainerhahnekamp
0
120
103 Early Hints
sugi_0000
1
260
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
970
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
110
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
950
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
return文におけるstd::moveについて
onihusube
1
1.3k
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
8
1.9k
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
490
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
How STYLIGHT went responsive
nonsquared
96
5.2k
Building Adaptive Systems
keathley
38
2.3k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Writing Fast Ruby
sferik
628
61k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
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