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
55
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
72
tidyverse tutorial 1
kur0cky
1
67
rating_introduction
kur0cky
1
830
motemote data science 1
kur0cky
1
520
Other Decks in Programming
See All in Programming
組織に自動テストを書く文化を根付かせる戦略(2024秋版) / Building Automated Test Culture 2024 Autumn Edition
twada
PRO
9
4.3k
Kotlinの好きなところ
kobaken0029
0
180
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
290
GPU Hash Table | レイトレ合宿10
yknishidate
0
360
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
910
レイトレ合宿10 レンダラー紹介 / Renderer Introduction, Ray Tracing Camp 10
shocker_0x15
0
680
プロジェクト新規参入者のリードタイム短縮の観点から見る、品質の高いコードとアーキテクチャを保つメリット
d_endo
1
890
のびしろを広げる巻き込まれ力:偶然を活かすキャリアの作り方/oso2024
takahashiikki
1
350
Synchronizationを支える技術
s_shimotori
1
140
watsonx.ai Dojo #3 プロンプトエンジニアリング入門
oniak3ibm
PRO
0
480
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
2
1.6k
ピクシブ百科事典のWebフロントエンドパフォーマンス改善
higara
0
190
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.6k
Documentation Writing (for coders)
carmenintech
65
4.4k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Making Projects Easy
brettharned
115
5.9k
Automating Front-end Workflow
addyosmani
1365
200k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Into the Great Unknown - MozCon
thekraken
31
1.4k
[RailsConf 2023] Rails as a piece of cake
palkan
50
4.8k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
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