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
RBC202003_Day1_Period3
Search
sakaue
March 19, 2020
Education
0
61
RBC202003_Day1_Period3
sakaue
March 19, 2020
Tweet
Share
More Decks by sakaue
See All by sakaue
SappoRo.R #11「R によるThe Multilingual Eye-tracking COrpus (MECO) の探索的データ分析」
sakaue
0
75
RBC202003_Day2_Period5
sakaue
0
32
RBC202003_Day2_Period6
sakaue
0
64
RBC202003_Day2_Period7
sakaue
0
61
Rbootcamp202003_Day2_p8.pdf
sakaue
0
67
RBC202003_Day1_Period1
sakaue
1
49
RBC202003_Day1_Period2
sakaue
0
52
RBC202003_Day1_Period4
sakaue
0
35
Other Decks in Education
See All in Education
The Gender Gap in the Technology Field and Efforts to Address It
codeforeveryone
0
170
"数学" をプログラミングしてもらう際に気をつけていること / Key Considerations When Programming "Mathematics"
guvalif
0
550
2024年度春学期 統計学 第14回 分布についての仮説を検証する ― 仮説検定(1) (2024. 7. 11)
akiraasano
PRO
0
160
Padlet opetuksessa
matleenalaakso
4
12k
week@tcue2024
nonxxxizm
0
510
Introduction - Lecture 1 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.7k
Medicare 101 for 2025
robinlee
PRO
0
200
Canva
matleenalaakso
0
420
Tableau トレーニング【株式会社ニジボックス】
nbkouhou
0
18k
Library Prefects 2024-2025
cbtlibrary
0
110
2024年度春学期 統計学 第15回 分布についての仮説を検証する ― 仮説検定(2) (2024. 7. 18)
akiraasano
PRO
0
140
Web 2.0 Patterns and Technologies - Lecture 8 - Web Technologies (1019888BNR)
signer
PRO
0
2.4k
Featured
See All Featured
A better future with KSS
kneath
238
17k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
How GitHub (no longer) Works
holman
310
140k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Building Your Own Lightsaber
phodgson
102
6.1k
RailsConf 2023
tenderlove
29
900
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
Designing the Hi-DPI Web
ddemaree
280
34k
GitHub's CSS Performance
jonrohan
1030
460k
Transcript
2020-03-19 ୈ3ݶ ϕΫτϧͱߦྻ bootcamp
Agenda 1. ϕΫτϧͱԿ͔ (20) 2. ߦྻͱԿ͔ (20) 3. વσʔλͱԿ͔ (15)
4. ԋशʹ͙࣍ԋश (35)
Agenda 1. ϕΫτϧͱԿ͔ (20) 2. ߦྻͱԿ͔ (20) 3. વσʔλͱԿ͔ (15)
4. ԋशʹ͙࣍ԋश (35)
ɹɹͱ͍͑ ม ໋ 1. ϕΫτϧͱԿ͔
มͱ ̍ͭҎ্ͷΛ ·ͱΊ͍ͯΕ͓ͯ͘ ʮശʯͷ͜ͱ 1. ϕΫτϧͱԿ͔
Ͱ ϕΫτϧͱݺΕ ෳͷΛ̍ͭʹ ·ͱΊͨͷΛࢦ͢ 1. ϕΫτϧͱԿ͔ ʢ̍࣍ݩྻͱݴΘΕΔ͜ͱʣ
•> hako <- c(1,2,3,4,5) •> hako • c() ؔɿcombine (
cf. https://twitter.com/#!/sakaue/status/193708048030760960 ) • Λ̍ͭʹ·ͱΊΔؔ • ٯʹॻ͍ͯʢҰԠʣOK 1. ϕΫτϧͱԿ͔
c()ؔͷ “<-” Կʁ hako <- c(1,2,3,4,5) ͷ “<-” ࠨ͖ͷҹʢˡʣ
Λදݱ ʢೖΕସ͑ͯಈ͖·͢ɻʮ=ʯ͑·͢ɻʣ 1. ϕΫτϧͱԿ͔
͍· “hako” ͱ͍͏໊લͷ ʮมʯͷதʹ 1͔Β5·Ͱͷ5ͭͷࣈ͕ ·ͱΊͯೖ͍ͬͯΔঢ়ଶ 1. ϕΫτϧͱԿ͔
1. ϕΫτϧͱԿ͔ • ·ͣϕΫτϧͷதʢཁૉʣΛ֬ೝ • ίϯιʔϧͰʮhakoʯͱͷΈೖྗ • ग़ྗ݁ՌΛ֬ೝ: 5ͭͷ͕͋Δ͔ •
ϕΫτϧΛ࡞ͬͨΒ͙֬͢ೝ (p. 55)
1. ϕΫτϧͱԿ͔ • ࣍ʹϕΫτϧͷ͞ʢཁૉʣΛ֬ೝ • ίϯιʔϧͰʮlength(hako)ʯͱೖྗ • ग़ྗ݁ՌΛ֬ೝ: 5 ͱग़Δ͔
• ϕΫτϧΛ࡞ͬͨΒ͙֬͢ೝ (p. 55)
1. ϕΫτϧͱԿ͔ • ϕΫτϧͷಛఆͷཁૉΛऔΓग़͢ • 3൪ͷཁૉ͚ͩΛऔΓग़͢ • hako[3] • 3
͚͕ͩදࣔ͞ΕΔ • 2൪͔Β4൪ͷཁૉΛऔΓग़͢ • hako[2 : 4] • 2, 3, 4 ͷ3ཁૉ͕දࣔ͞ΕΔ (p. 56)
1. ϕΫτϧͱԿ͔ • ϕΫτϧΛͬͨܭࢉ • ͯ͢ͷཁૉΛ2ഒ͢Δ • hako * 2
• ผͷϕΫτϧΛ࡞ͦ͠ΕͧΕΛ͢ • hako2 <- c(6, 7, 8, 9, 10) • hako + hako2 • ͦΕͧΕͷཁૉಉ͕࢜͞ΕΔ • ཁૉ͕͚ܽΔͱΤϥʔ͕ग़Δ (p. 56)
1. ϕΫτϧͱԿ͔ • ϕΫτϧෳͷΛ·ͱΊͨͷ • σʔλΛ݁߹͢Δ • vector.1 <- append(hako,
hako2) • vector.1 ͱೖྗ͠தΛ֬ೝ • vector.2 <- append(hako2, hako) • vector.2 ͱೖྗ͠தΛ֬ೝ • ࢦఆͨ͠ॱং௨Γʹ݁߹͞ΕΔ (p. 56)
Ͱ ෳͷΛ̍ͭʹ ·ͱΊͨͷΛ ϕΫτϧͱݺͿ 1. ϕΫτϧͱԿ͔ ʢ̍࣍ݩྻͱݴΘΕΔ͜ͱʣ
Agenda 1. ϕΫτϧͱԿ͔ (20) 2. ߦྻͱԿ͔ (20) 3. વσʔλͱԿ͔ (15)
4. ԋशʹ͙࣍ԋश (35)
Agenda 1. ϕΫτϧͱԿ͔ (20) 2. ߦྻͱԿ͔ (20) 3. વσʔλͱԿ͔ (15)
4. ԋशʹ͙࣍ԋश (35)
2. ߦྻͱԿ͔ ͖͞΄Ͳ ҰߦͰΛ·ͱΊͨ ϕΫτϧΛհ͠·͕ͨ͠
࣮ࡍͷσʔλ ෳߦ(ྻ)͋Δͣ 2. ߦྻͱԿ͔
ྫ͑... •ͱମॏ •ྸͱऩ •֮͑ͨ୯ޠͱTOEIC είΞ 2. ߦྻͱԿ͔
දʹ͢Ε... ਓ ମॏ A 180 75 B 170 65
C 165 60 D 175 70 E 190 80 2. ߦྻͱԿ͔
ෳͷߦྻͰද͞ΕΔ σʔλΛѻ͏ͨΊʹ ɹɹͰʮߦྻʯΛ͏ 2. ߦྻͱԿ͔
ߦྻͱ ͕ॎԣʹฒΒΕͨͷ 2. ߦྻͱԿ͔
1 2 3 4 5 6 7 8 9
ߦ
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
ྻ
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
ͦΜͳߦྻΛѻ͏ͨΊʹ matrix() ؔ Λ͏ 2. ߦྻͱԿ͔
•matrix() ؔ: ߦྻΛ࡞Δؔ •matrix(ཁૉ, ߦͷ, ྻͷ) •σϑΥϧτͰྻํʹஔ 2. ߦྻͱԿ͔
• ϕΫτϧΛ࡞͔ͯ͠Βߦྻʹม Part 1 • hako3 <- c(1, 2, 3,
4, 5, 6, 7, 8, 9) • matrix.1 <- matrix(hako3, nrow=3, ncol=3) • Ҿʢargumentʣͱͯ͠ߦྻΛࢦఆ • nrow: ߦΛࢦఆɼncol: ྻΛࢦఆ • matrix.1 ͚ͩΛೖྗͯ͠தΛ֬ೝ 2. ߦྻͱԿ͔
• ϕΫτϧΛ࡞͔ͯ͠Βߦྻʹม Part 2 • matrix.2 <- matrix(hako3, nrow=3, ncol=3,
byrow= TRUE) • byrow = TRUE ʹΑΓԣํཁૉΛஔ ɹ • nrow: ߦΛࢦఆɼncol: ྻΛࢦఆ • matrix.2 ͚ͩΛೖྗͯ͠தΛ֬ೝ 2. ߦྻͱԿ͔
1 4 7 2 5 8 3 6 9 matrix(1:9,nrow=3,ncol=3)
2. ߦྻͱԿ͔
1 2 3 4 5 6 7 8 9 matrix(1:9,nrow=3,ncol=3,byrow=TRUE)
2. ߦྻͱԿ͔
2. ߦྻͱԿ͔ • ߦྻͷߦྻΛΔʹ • nrow(matrix.2) #ߦͷΈ֬ೝ • ncol(matrix.2) #ྻͷΈ֬ೝ
• dim(matrix.2) #ߦͱྻΛಉ࣌ʹ֬ೝ
2. ߦྻͱԿ͔ • ߦྻΛͬͨܭࢉ • matrix.2 + 1 #֤ཁૉʹ1Λ͢ •
ผͷߦྻΛ࡞ͦ͠ΕͧΕΛ͢ • matrix.3 <- matrix(c(10:18), nrow=3, ncol=3, byrow=TRUE) • matrix.2 + matrix.3 • 9ͭͷཁૉ͕͞Ε͍ͯΔ͔֬ೝ
2. ߦྻͱԿ͔ • ߦྻͷ݁߹ • rbind() ؔ: ߦํʢԼʣʹߦྻΛ݁߹ • rbind(matrix.2,
matrix.3) • cbind() ؔ: ྻํʢӈʣʹߦྻΛ݁߹ • cbind(matrix.2, matrix.3)
2. ߦྻͱԿ͔ • ߦྻͷཁૉΛऔΓग़͢ • matrix.2[2, 3] #2ߦͷ3ྻʹ͋Δཁૉ • matrix.2[2,
] #2ߦͷཁૉͯ͢ • matrix.2[, 3] #3ྻͷཁૉͯ͢ • matrix.2[-2, ] #2ߦ<Ҏ֎>ͷཁૉͯ͢ • matrix.2[, -3] #3ྻ<Ҏ֎>ͷཁૉͯ͢
2. ߦྻͱԿ͔ • ߦྻΛసஔ͢ΔʢߦͱྻΛೖΕସ͑Δʣ • t(matrix.2) • matrix.2 ͷ࣮ߦ݁Ռͱൺֱ
2. ߦྻͱԿ͔ • ߦྻʹϥϕϧʢ໊લʣΛ͚ͭΔ • rownames(matrix.2) <- c("R1", "R2", "R3")
• ߦϥϕϧͷ༩ • colnames(matrix.2) <- c("C1", "C2", "C3") • ྻϥϕϧͷ༩ • matrix.2 Λೖྗ݁͠ՌΛ֬ೝ
ߦྻ·ͱΊ • ԣํ͕ߦɺॎํ͕ྻ • σϑΥϧτͰͷͷฒͼʹҙ • ඞཁͳཁૉΛదٓऔΓग़ͯ͠Λ֬ೝ
Agenda 1. ϕΫτϧͱԿ͔ (20) 2. ߦྻͱԿ͔ (20) 3. વσʔλͱԿ͔ (15)
4. ԋशʹ͙࣍ԋश (35)
Agenda 1. ϕΫτϧͱԿ͔ (20) 2. ߦྻͱԿ͔ (20) 3. વσʔλͱԿ͔ (15)
4. ԋशʹ͙࣍ԋश (35)
3. વσʔλͱԿ͔ • R քͷਆɼHadley Wickham ࢯఏএͷ "Tidy Data" •
จ: http://vita.had.co.nz/papers/tidy-data.html • ࢀߟ: http://id.fnshr.info/2017/01/09/tidy-data-intro/ • ʮ1ྻʹʢॎํʣ1มʯͷܗࣜʹ͢Δ͜ͱ • ੳ༻ͷσʔλܗࣜ͜Ε͕େݪଇ • มΛԣʢߦʣํʹฒͨΓ͠ͳ͍ • Excel Ͱηϧͷ݁߹ͳΜͧ͠ΑͬͨΒ...ʢౖʣ
ʘ݄ 4݄ 5݄ 6݄ H30 124 183 241 H31 205
367 307 R01 582 759 998 3. વσʔλͱԿ͔ • Α͘ݟ͔͚ΔλΠϓͷද • ਓʹݟͤʢͯղऍ͢ʣΔදͱͯ͠ OK • σʔλੳ༻ͷදͱͯ͠ NG • ॎͱԣʹม͕ަࠩͨ͠ঢ়ଶ͔ͩΒ
݄ ΞΫηε H30 4 124 H30 5 183 H30
6 241 H31 4 205 H31 5 367 H31 6 307 R01 4 582 R01 5 759 R01 6 998 3. વσʔλͱԿ͔ • ੳ༻ʹʮ1ྻʹʢॎํʣ1มʯ • 1ߦʢԣํʣʹ1έʔεɾ1Ϩίʔυ • ݄ΛԣʢߦʣํʹฒͨΓ͠ͳ͍
• ࢝Ί͔Βવσʔλʹͳ͍ͬͯΔ͜ͱগͳ͍(?) • ͦ͏ͨ͠σʔλΛมܗɾཧ͢ΔͨΊʹɼR Ͱ "tidyverse" ͱ͍͏ύοέʔδ͕ར༻Մೳ • tidyverse ʹؚ·ΕΔύοέʔδΛ·ͱΊͯΠϯ
ετʔϧ͢ΔͨΊͷύοέʔδ • ggplot2: άϥϑඳը • dplyr: σʔλૢ࡞ʢ݅நग़ɼྻՃͳͲʣ • tidyr: વσʔλ࡞ • ͦͷଞଟͷύοέʔδ͋Γ 3. વσʔλͱԿ͔
• ຊߨशձͰ "Tidy Data" ͷઆ໌ͱɼ"tidyverse" ύοέʔδͷհͷΈʢૢ࡞͕Ұ෦ಛघͳͨΊʣ • େྔͷσʔλΛܗ͢Δࡍɼ΄΅ඞਢͷύο έʔδͱͳΓͭͭ͋Δ •
ࢀߟ1: https://r4ds.had.co.nz/ (R for Data Science) • ࢀߟ2: https://moderndive.com/index.html ɹɹɹɹɹɹ (A moderndive into R and the tidyverse) • େࣄͳ͜ͱɼʮݟͯղऍ͢ΔදʯͱʮσʔλΛ อଘ͢ΔදʯʢʹTidy DataʣΛ۠ผͯ͠อଘͯ͠ ͓͘͜ͱ 3. વσʔλͱԿ͔
Agenda 1. ϕΫτϧͱԿ͔ (20) 2. ߦྻͱԿ͔ (20) 3. વσʔλͱԿ͔ (15)
4. ԋशʹ͙࣍ԋश (35)
Agenda 1. ϕΫτϧͱԿ͔ (20) 2. ߦྻͱԿ͔ (20) 3. વσʔλͱԿ͔ (15)
4. ԋशʹ͙࣍ԋश (35)
4. ԋशʹ͙࣍ԋश 1. ͱମॏͷߦྻΛ࡞ΔʢਓΛআ͘ʣ ਓ ମॏ A 180 75
B 170 65 C 165 60 D 175 70 E 190 80
ώϯτ 1. c() ؔͰɺΛ࿈݁ 2. matrix() ؔͰɺߦྻʹม • ʮ5ߦͰ2ྻʯʹ͢Δͱ͍͏ࢦఆΛ͢Δ 3.
มʹೖ͢Δ͜ͱΛ͓Εͳ͘ 4. ԋशʹ͙࣍ԋश
> karada ͱೖྗͯ͠ มͷதΛ֬ೝ
2. 1͔Β50·ͰͷΛɼ10ߦ5ྻͷߦྻʹม 3. 2 Ͱ࡞ͨ͠ߦྻͷ7ߦͷཁૉΛऔΓग़͢ 4. 3 ͰऔΓग़ͨ͠7ߦͷཁૉͷ߹ܭΛࢉग़͢Δʢ1ߦͰʣ 5. 2
Ͱ࡞ͨ͠ߦྻͷ3ྻͷཁૉΛऔΓग़͢ 6. 2 Ͱ࡞ͨ͠ߦྻͷ5ߦʻҎ֎ʼͷཁૉΛऔΓग़͢ 7. 2 Ͱ࡞ͨ͠ߦྻͷ2ߦͱ7ߦͷཁૉΛಉ࣌ʹऔΓग़͢ 8. 2 Ͱ࡞ͨ͠ߦྻͷ2ྻͱ4ྻͷཁૉΛಉ࣌ʹऔΓग़͢ 9. 2 Ͱ࡞ͨ͠ߦྻͷ2ྻͱ4ྻͷཁૉͷฏۉΛࢉग़͢Δ 10. 2 Ͱ࡞ͨ͠ߦྻʹϥϕϧΛ͚ͭΔʢR1 … R10, C1 … C5ʣ 4. ԋशʹ͙࣍ԋश
2. matrix() ؔɼҾͷ nrow / ncol, byrow ʹ༻৺ 3. ΧοίͷछྨͱΧϯϚͷҐஔʹҙ
4. ߹ܭΛٻΊΔʹɼS** ؔ 5. ΧοίͷछྨͱΧϯϚͷҐஔʹҙ 6. ʮҎ֎ʯɼϋΠϑϯͰࢦఆ 7. ಉ࣌ʹࢦఆ͢Δͱ͖ɼc() ؔΛΈ߹Θ࣮ͤͯߦ 8. ಉ࣌ʹࢦఆ͢Δͱ͖ɼc() ؔΛΈ߹Θ࣮ͤͯߦ 9. ฏۉΛٻΊΔʹɼm*** ؔ 10. rownames/colnames ͰɼจࣈྻʹೋॏҾ༻ූΛه 4. ԋशʹ͙࣍ԋशʢώϯτʣ
Enjoy ! twitter: @sakaue e-mail: tsakaue<AT>hiroshima-u.ac.jp