Upgrade to Pro — share decks privately, control downloads, hide ads and more …

初心者こそRStudioを使ったほうがいい理由/NagoyaR17

Yu Tamura
December 10, 2016

 初心者こそRStudioを使ったほうがいい理由/NagoyaR17

初心者こそRStudioを使ったほうがいい理由をランキング形式で紹介します。

Yu Tamura

December 10, 2016
Tweet

More Decks by Yu Tamura

Other Decks in Programming

Transcript

  1. ॳ৺ऀͦ͜RStudioΛ
    ࢖ͬͨ΄͏͕͍͍ཧ༝
    2016.12.10. Nagoya.R #17
    ໊ݹ԰େֶେֶӃࠃࡍ։ൃݚڀՊ D3 ాଜ༞
    1

    View full-size slide

  2. ֓ཁ
    • ର৅
    • ʮRͷ͜ͱ͸·ͩΑ͘Θ͔Βͳ͍͚ͲɼͳΜ͔ศར
    Β͍͠…Ͱ΋RίϫΠ…ʯͱࢥ͍ͬͯΔͦ͜ͷ͋ͳ
    ͨ
    • ಺༰
    • RStudio͕ศརŦƄūŖͱࢥ͏ͱ͜ΖΛಠஅͱภݟͰબ
    ΜͰϥϯΩϯάܗࣜͰ͝঺հ
    2

    View full-size slide

  3. ͓͜ͱΘΓ
    • ຊൃදʹ͍ͭͯҎԼͷ͜ͱ͸͓߇͍͑ͩ͘͞
    • ੜRΛ͕ͪΌ͕ͪΌ࢖͍౗͍ͯ͠Δਓ͔Β
    • ʮͦΕͬͯผʹੜRͰ΋͍͍͡ΌΜʯ
    • ʮੜRʹ׳ΕͯΔ͔ΒٯʹRStudio࢖͍ͮΒ͍ʯ
    • ੜRΛ࢖ͬͯ৬ਓܳతͳ͜ͱΛͳ͞Δํ͔Βͷ
    • ʮͰ΋RStudioͩͱ̋̋͸Ͱ͖ͳ͍ʯ
    3

    View full-size slide

  4. ීஈ͸͠ͳ͍ࣗݾ঺հ
    • ໊લ
    • ాଜ༞
    • ॴଐ
    • ໊ݹ԰େֶେֶӃࠃࡍ։ൃݚڀՊത࢜ޙظ՝ఔ
    • ݚڀ෼໺
    • ୈೋݴޠशಘɼ৺ཧݴޠֶɼจ๏ࢦಋ
    • Rྺ
    • ҰੜΤϯυϢʔβʔʢ4೥͘Β͍ʣ
    4

    View full-size slide

  5. RStudioͬͯͳʹ
    • ؆୯ʹݴ͏ͱ…
    • RͷGUIʢͭ·ΓΫϦοΫͰϙνϙνͰ͖Δ͜
    ͱʣΛॆ࣮ͤͨ͞Γ৭ʑศརͳػೳΛ࣮૷͠
    ͨΓͯ͠ੜͷRΛΑΓ࢖͍΍ͨ͘͢͠ϓϩάϥ
    Ϝ
    5

    View full-size slide

  6. ຊൃදͷ໨ඪ
    • RStudioͷศརͳͱ͜ΖϥϯΩϯάΛฉ͍ͨΈͳ
    ͞ΜʹɼʮRStudio࢖ͬͯΈΑ͏͔ͳ…ʯͱࢥͬ
    ͯ΋Β͏͜ͱ
    6

    View full-size slide

  7. ͬͦ͘͞Ͱ͕͢·ͣ͸
    ୈ5Ґ͔Βʂ
    7

    View full-size slide

  8. ୈ5Ґ
    TABͷิ׬ػೳͷ༏͕͠͞ҧ͏
    8

    View full-size slide

  9. ୈ5ҐɹTABิ׬ػೳͷ༏͠͞
    • Χοίͷด͡๨ΕɼΫΥʔςʔγϣϯϚʔΫͷ
    ͱ͡๨ΕͳͲ͕ͳ͍Α͏։͍ͨΒดͯ͘͡ΕΔ
    • ͞Βʹؔ਺ɼม਺ɼσʔλϑϨʔϜ಺ͷม਺ͳ
    Ͳ΋ิ׬ͯ͘͠ΕΔ
    9

    View full-size slide

  10. ୈ5ҐɹTABิ׬ػೳͷ༏͠͞
    • ੜRͷ৔߹
    • ͦͷؔ਺ͰඞཁͳҾ਺͸ҰԠݟΕΔͱ͍͏༏͠͞͸࣋ͪ߹Θ͍ͤͯΔ
    • ͨͩ͠ɼͨͱ͑͹familyͱ͍͏Ҿ਺ʹԿΛೖΕΕ͹͍͍ͷ͔͸Θ͔Β
    ͳ͍
    10

    View full-size slide

  11. ୈ5ҐɹTABิ׬ػೳͷ༏͠͞
    • RStudioͷ৔߹
    • Ҿ਺ͷҰཡ͕ΈΕΔ্ʹɼϚ΢εΦʔόʔͰͦͷҾ਺ͷઆ໌·Ͱ΋ද
    ࣔ͞ΕΔ
    • F1ԡͤ͹ӈԼͷ΢Οϯυ΢Ͱϔϧϓ͕ݟΕΔ
    11

    View full-size slide

  12. ୈ5ҐɹTABิ׬ػೳͷ༏͠͞
    • RStudioͷ৔߹
    • σʔλϑϨʔϜͷ৔߹ɼ$·Ͱଧͯ͹ͦͷσʔλϑϨʔϜ಺ͷม਺Ұ
    ཡΛදࣔͯ͘͠ΕΔ
    • ੜRͰ΋ಉ༷ͷػೳ͸͋Δ͕ɼҰཡΛදࣔ͢Δ͚ͩͰબ୒ͯ͠ิ׬͢
    Δ͜ͱ͸Ͱ͖ͳ͍
    12

    View full-size slide

  13. ͍ͭͮͯୈ4Ґʂ
    13

    View full-size slide

  14. ୈ4Ґ
    ৭Μͳ΢Οϯυ΢͕
    ͪ͝Όͪ͝Ό͠ͳ͍
    14

    View full-size slide

  15. ୈ4Ґɹͪ͝Όͪ͝Ό͠ͳ͍
    • εΫϦϓτɼϓϩοτͷग़ྗ΍ΧϨϯτσΟϨΫτϦɼίϯιʔϧɼ
    ม਺ͷ֬ೝ͕σϑΥϧτͰ෼ׂ͞ΕͨϖΠϯͰදࣔ͞ΕΔͷͰɼεο
    ΩϦ͍ͯͯ͠࡞ۀ͕ḿΔʢ˞ݸਓͷײ૝Ͱ͢ʣ
    εΫϦϓτ
    ίϯιʔϧ
    ม਺ͷ֬ೝ
    ΧϨϯτσΟϨ
    ΫτϦ΍ϓϩο
    τɼύοέʔδ
    ɼ
    ϔϧϓը໘ͳͲ
    15

    View full-size slide

  16. ͔͜͜Βϕετ̏ʂ
    ͍ͭͮͯୈ3Ґʂ
    16

    View full-size slide

  17. ୈ3Ґ
    ࡞ͬͨม਺ͷ֬ೝָ͕
    17

    View full-size slide

  18. ୈ3Ґɹ࡞ͬͨม਺ͷ֬ೝָ͕
    18
    ͍·ͲΜͳσʔλ΍ม਺Λ͍࣋ͬͯΔͷ͔
    ʢΦϒδΣΫτͷ਺΍ม਺ͷ਺·Ͱ΋͕ʣͻͱ໨ͰΘ͔Δ

    View full-size slide

  19. ୈ3Ґɹ࡞ͬͨม਺ͷ֬ೝָ͕
    19
    ͜ͷ੨͍໼ҹͷ෦෼
    ΛΫϦοΫ͢Δͱɼσʔ
    λͷߏ଄͕ݟΕΔ
    ʢstrؔ਺ͱಉ͡ʣ

    View full-size slide

  20. ୈ3Ґɹ࡞ͬͨม਺ͷ֬ೝָ͕
    20
    ӈଆͷϖΠϯͰσʔλΛΫϦοΫ͢ΔͱλϒͰࠨ্ͷϖΠϯʹදࣔ͞ΕΔ

    View full-size slide

  21. ͍ͭͮͯୈ2Ґʂ
    21

    View full-size slide

  22. ୈ2Ґ
    σʔλͷಡΈࠐΈͱ֬ೝָ͕
    22

    View full-size slide

  23. ୈ2ҐɹσʔλͷಡΈࠐΈ
    • Rॳ৺ऀ͕ͭ·ͮ͘ϙΠϯτୈ1Ґʢ˞ݸਓͷײ
    ૝Ͱ͢ʣ͸σʔλͷಡΈࠐΈ
    • read.csv()΍read.table()ͳͲΛΑ͘࢖͏ͱࢥ͍
    ·͕͢ɼςΩετϑΝΠϧ΍΢ΣϒURL͔Βͷ
    σʔλͷಡΈࠐΈ͕ɼRStudioͳΒGUI͔ΒͰ
    ͖ͯ͠·͏
    23

    View full-size slide

  24. ؓ࿩ٳ୊
    24

    View full-size slide

  25. csvϑΝΠϧ…ʁʁʁ
    25

    View full-size slide

  26. csvϑΝΠϧ…ʁʁʁ
    26

    View full-size slide

  27. csvϑΝΠϧ…ʁʁʁ
    RʹσʔλΛಡΈࠐΉͱ͖͸csvϑΝΠϧʹ͓ͯ͘͠ͷ͕Φεεϝ
    27

    View full-size slide

  28. ͦΜͳcsvϑΝΠϧΛָʹಡΈ
    ࠐΊΔ্ʹσʔληοτΛࢹ
    ֮తʹݟΔ͜ͱ΋Ͱ͖Δ
    28

    View full-size slide

  29. ୈ2ҐɹσʔλͷಡΈࠐΈ
    Tools -> Import Dataset -> From text file…·ͨ͸
    29

    View full-size slide

  30. ಡΈࠐΊ͍ͯΔ͔ͷ֬ೝ΋Ͱ͖ͪΌ͏(1000ߦ·Ͱʣ
    ୈ2ҐɹσʔλͷಡΈࠐΈ
    30

    View full-size slide

  31. ಊʑͷୈ1Ґʂ
    31

    View full-size slide

  32. ͷલʹ൪֎ฤ
    32

    View full-size slide

  33. ൪֎ฤɹϫʔΩϯάσΟϨΫτϦͷઃఆ
    • Rॳ৺ऀ͕ͭ·ͮ͘ϙΠϯτୈ2Ґʢ˞ݸਓͷײ
    ૝Ͱ͢ʣ͸σʔλͷಡΈࠐΈ
    • setwdͩͱϑΝΠϧύεͷࢦఆ͕ΊΜͲ͏…
    • ϑΝΠϧ->σΟϨΫτϦͷมߋͰͰ͖Δ͚Ͳ…
    33

    View full-size slide

  34. RStudioͳΒ
    Ctrl+Shift+HͰ͍͚ͪΌ͏
    34

    View full-size slide

  35. ӈԼͷFiles͔Βࢦఆ͍ͨ͠ϑΥϧμΛ
    બ΂͹؆୯ʹWDΛઃఆͰ͖Δ
    38

    View full-size slide

  36. ͓଴ͨͤ͠·ͨ͠ʂ
    ಊʑͷୈ1Ґʂ
    39

    View full-size slide

  37. ୈ1Ґ
    ϓϩδΣΫτػೳͰ
    ࡞ۀͷ؅ཧָ͕
    40

    View full-size slide

  38. ϓϩδΣΫτʁʁʁ
    41

    View full-size slide

  39. • RStudioͰԿ͔Λ෼ੳ͢Δͱ͖ͷ؀ڥʁͷΑ͏ͳ
    ΋ͷͷ୯Ґ
    • ಛఆͷσΟϨΫτϦʢϑΥϧμʣʹ࡞ΒΕΔ
    • ΋ͱ΋ͱ͋ΔϑΥϧμͰ΋ྑ͍͠ϓϩδΣΫτ
    Λ࡞Δࡍʹ৽͘͠ϑΥϧμΛ࡞ͬͯ΋Α͍
    42
    ϓϩδΣΫτʁʁʁ

    View full-size slide

  40. ୈ1Ґ
    ϓϩδΣΫτػೳͰ
    ࡞ۀͷ؅ཧָ͕
    43

    View full-size slide

  41. ୈ1ҐɹϓϩδΣΫτػೳ
    • ϓϩδΣΫτͷ࡞੒͸RStudioͰ࡞ۀΛ࢝ΊΔͱ͖ʹ
    ඞͣ΍Δ΂͖͜ͱͰ͋Γͦͯ͠Ұ൪ศརʢ˞ݸਓͷ
    ײ૝Ͱ͢ʣ
    • ࣮͸͖ͬ͞ͷϫʔΩϯάσΟϨΫτϦͷઃఆͳͲ΋
    ͜ͷϓϩδΣΫτػೳ͕͋Ε͹΋͏೰·͞ΕΔ͜ͱ
    ͸ͳ͍
    • ࡞ۀɼ࢓ࣄɼݚڀ͝ͱʹϓϩδΣΫτΛ࡞Δͷ͕Φ
    εεϝ
    44

    View full-size slide

  42. ୈ1ҐɹϓϩδΣΫτػೳ
    45
    ৽͘͠࡞ΔͳΒݚڀ΍࢓ࣄ͝ͱͷ໊
    લΛ͚ͭͨσΟϨΫτϦΛ͚ͭΔ
    (->New Directory->Empty Projectʣ
    ΋͏͢Ͱʹ࡞ۀʹؔ࿈͢ΔϑΝΠϧ
    ͳͲͷೖͬͨϑΥϧμ͕͋ΔͳΒͦ
    ͜ʹ࡞Δ(->Exsiting Directory)

    View full-size slide

  43. ୈ1ҐɹϓϩδΣΫτػೳ
    46
    ͜Μͳײ͡ͰNew ProjectΛ࡞Δͱ…

    View full-size slide

  44. ୈ1ҐɹϓϩδΣΫτػೳ
    47
    ~/Dropbox/soldier/boss/boss.Rproj
    ͋Εɼࠨଆ͕ͳΜ͔͖ͬ͞ͱҧ͏ʁʁʁʁʁ

    View full-size slide

  45. ୈ1ҐɹϓϩδΣΫτػೳ
    48
    εΫϦϓτ
    ίϯιʔϧ
    ม਺ͷ֬ೝ
    ΧϨϯτσΟϨ
    ΫτϦ΍ϓϩο
    τɼύοέʔδ
    ɼ
    ϔϧϓը໘ͳͲ

    View full-size slide

  46. ୈ1ҐɹϓϩδΣΫτػೳ
    • ϓϩδΣΫτΛ৽͘͠࡞ͬͨΒɼ·ͣ࠷ॳʹඞ
    ͣ৽͍͠RεΫϦϓτϑΝΠϧΛ࡞Δʢࢀরɿ
    ʮίϯιʔϧϕλଧͪଔۀɿεΫϦϓτΤσΟλ
    Λ࢖͓͏ʯʢhttps://speakerdeck.com/tam07pb915/nagoyar14)
    • ͦͯ͠ඞ໊ͣલΛ͚ͭͯอଘ
    49

    View full-size slide

  47. ୈ1ҐɹϓϩδΣΫτػೳ
    50
    ࡞ͬͨεΫϦϓτ্ʹίʔυΛॻ͍͍ͯ͘

    View full-size slide

  48. ୈ1ҐɹϓϩδΣΫτػೳ
    • RStudioΛऴྃ͢Δͱ͖
    • ϫʔΫεϖʔεΛอଘ͢Ε͹ม਺ͷத਎͸อଘ͞ΕΔ
    • ϫʔΫεϖʔεΛอଘ͠ͳͯ͘΋εΫϦϓτ͸ʢ͖ͪ
    Μͱอଘ͞Ε͍ͯΕ͹ʣ͍͍ͪͪ։͔ͳͯ͘΋࣍ʹ
    ϓϩδΣΫτΛ։͘ͱ͖ʹҰॹʹ։͘
    • ม਺࢒͓͖͍ͯͨ͠ͷʹϫʔΫεϖʔεอଘ͠๨Ε
    ͨ…
    51

    View full-size slide

  49. ͦΜͳͱ͖΋
    RStudioͳΒ…
    52

    View full-size slide

  50. ୈ1ҐɹϓϩδΣΫτػೳ
    • History͕อଘ͞ΕΔ
    • ΍Γ௚͍ͨ͠ίʔυΛબ୒
    • To ConsoleͰͦͷίʔυΛίϯιʔϧʹ౉͢
    • To SourceͰεΫϦϓτʹͦͷίʔυΛ౉͢
    • ͋ͱ͸ͦͷίʔυΛ࣮ߦ͢Δ͚ͩ
    53
    ※ੜRʹ΋ཤྺͷอଘ
    ͱಡΈࠐΈػೳ͸͋Δ
    ͱ͍͑͹͋Δ

    View full-size slide

  51. ͓ΘΓʹ
    • ·ͱΊ
    • ͱʹ͔͘RStudio࢖͏ͱศརͳ͜ͱ͕ͨ͘͞Μ͋Δ
    • ʮͲ͏ͯ͠΋࢖͍ͨ͘ͳ͍ʯͱ͍͏ཧ༝͕໌֬ʹ
    ͋ΔͳΒͱ΋͔͘ɼॳ৺ऀͦ͜RStudioΛ࢖ͬͨ΄
    ͏͕ઈରʹ͍͍
    • ͨͿΜR࢖Θͣݏ͍ͷ൒෼͘Β͍͸RStudio࢖͑͹
    ݮΔʢ˞ݸਓͷײ૝Ͱ͢ʣ
    54

    View full-size slide

  52. ॳ৺ऀͦ͜RStudioΛ࢖ͬͨ
    ΄͏͕͍͍ཧ༝
    contact info
    ాଜ ༞
    ໊ݹ԰େֶେֶӃੜ
    [email protected]
    http://www.tamurayu.wordpress.com/
    1ҐɹϓϩδΣΫτػೳ
    2ҐɹσʔλͷಡΈࠐΈͱ֬
    ೝָ͕
    3Ґɹ࡞ͬͨม਺ͷ֬ೝָ͕
    4Ґɹͪ͝Όͪ͝Ό͠ͳ͍
    5ҐɹTABิ׬ػೳͷ༏͠͞
    55

    View full-size slide