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

RBC202003_Day1_Period1

sakaue
March 19, 2020

 RBC202003_Day1_Period1

sakaue

March 19, 2020
Tweet

More Decks by sakaue

Other Decks in Education

Transcript

  1. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  2. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  3. 1.ɹɹɹ֓࿦:ɹ ɹɹͱ͸Կ͔ • ౷ܭॲཧΛ໨తͱ͢Δϓϩάϥϛϯάݴޠ • ౷ܭܭࢉͷڞ௨ݴޠ (linga franca) • cf.

    S ݴޠ • ແঈʴΦʔϓϯιʔεͷιϑτ΢ΣΞ • ࡞ऀɿRoss Ihaka & Robert Gentleman (R & R) • Ross Ihaka and Robert Gentleman. R: A language for data analysis and graphics. Journal of Computational and Graphical Statistics, 5(3):299-314, 1996. • http://biostat.mc.vanderbilt.edu/twiki/pub/Main/JeffreyHorner/JCGSR.pdf
  4. • ͢΂ͯͷॲཧɾ෼ੳ͕ R ͷΈͰ׬݁ʢՄೳʣ • <-> Editor + Excel (+

    UNIX) + R + ͳΜ΍͔Μ΍ • ϓϩάϥϛϯάͷجૅཆ੒ʹ༗ޮ • --> Python, Perl, ... ผݴޠʹԠ༻Մೳ • ࡞ਤ͕ඒ͍͠ʢʴMac ͳΒϑΥϯτ΋ʣ • Excel ͷ࡞ਤ͸Ұൠʹ (‘A`)řƄō- 1.ɹɹɹ֓࿦:ɹɹɹͷεεϝ
  5. • σʔλͷऔΓѻ͍ํʹ༻৺͢Δ • Excel ʹ೚͖ͤͬΓͱ͠ͳ͍ • σʔλͷॲཧաఔΛ͸͖ͬΓͤ͞Δ • Excel ʹ೚͖ͤͬΓʹ͠ͳ͍

    • σʔλͷ෼෍ΛΑ͘؍࡯͢Δ • Excel ʹ೚͖ͤͬΓʹ͠ͳ͍ 1.ɹɹɹ֓࿦:ɹɹɹͷεεϝ
  6. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  7. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  8. 1. http://www.r-project.org/ ʹΞΫηε 2. “download R” ΛΫϦοΫ 3. JAPAN ͷத͔Β̍ͭΛબͿ

    4. OS ʹԠͨ͡ϦϯΫΛΫϦοΫ 2. ɹ ͷ install / update / uninstall
  9. • Windows: : http://cran.ism.ac.jp/bin/windows/base/ •ʮDownload R 3.6.3 for WindowsʯΛΫϦοΫ •

    macOS: http://cran.ism.ac.jp/bin/macosx/ •ʮR-3.6.3.pkgʯΛΫϦοΫ 2. ɹ ͷ install / update / uninstall μ΢ϯϩʔυޙ͸ɼଞͷΞϓϦͱಉ༷ʹ ʮ࣍΁ʯͷϘλϯΛԡͯ͠ઌʹ͢͢ΊΔͷΈ
  10. • Windows: http://cran.ism.ac.jp/bin/windows/base/old • “Previous releases” ͷϦϯΫΛΫϦοΫ • MacOS: http://cran.ism.ac.jp/bin/macosx/old

    • “old” ͷϦϯΫΛΫϦοΫ 2. ɹ ͷ install / update / uninstall ΋͠ɼݹ͍όʔδϣϯͷ R ͕ཉ͍͠ͱ͖͸… ʢݹ͍ PCɾOS ͕࢒͍ͬͯΔඞཁ͋Γʣ
  11. • ηΩϡϦςΟ্ͷ໰୊͕ͳ͍ݶΓ͸ɼ Ή΍Έʹߋ৽͠ͳ͍ํ͕ແ೉ • ύοέʔδʢ෇Ճػೳʣͷಈ࡞ෆྑճආ • R X.Y.Z ͷ Z

    ͷ஋ͷߋ৽ͳΒ΄΅ OK • ৽چͷڞଘ͸Մೳ • Windows/Mac: ผ໊ͰΠϯετʔϧ • ͨͩ͠ɼԿ͕Ͳ͏ڞ༗͞Ε͍ͯΔ͔͸ෆ໌ 2. ɹ ͷ install / update / uninstall
  12. • Windows 8.1/10 • ίϯύωˠϓϩάϥϜͷΞϯΠϯετʔϧ • ελʔτϝχϡʔ্ͰӈΫϦοΫͰʮΞϯΠϯετʔϧʯ • macOS •

    /Applications ʹ͋Δ ɹɹ ΞΠίϯ…͚ͩͰ͸ࡁ·ͳ͍
 ͷͰɼ AppCleaner ౳ͷΞϓϦ࡟আΞϓϦΛ࢖͏ 2. ɹ ͷ install / update / uninstall
  13. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  14. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  15. • Windows 8.1/10 • Windows → R → R 3.6.3

    Λબ୒ • 32 bit ൛ (i386), 64 bit (x64) ൛ Λ۠ผ • MacOS • /Applications ಺ͷ ΛμϒϧΫϦοΫ • Spotlight ͰʮRʯͱೖྗͯ͠ [Enter] 3. ɹ ͷ جຊૢ࡞ ͳʹ͸ͱ΋͋Ε·ͣىಈ
  16. ·ͣ͸࢛ଇԋࢉ • ࣍ͷࣜΛೖྗ͠ [Enter]ʢ> ͸ೖྗෆཁʣ • > 3+5 [Enter] •

    > 10-3 [Enter] • > 2*3 [Enter] • > 100/20 [Enter] • > (12 + 34 -56) * 78 / 90 [Enter] 3. ɹ ͷ جຊૢ࡞
  17. ·ͱΊͯॲཧͳΒηϛίϩϯͰ࿈݁ • ࣍ͷࣜΛೖྗ͠ [Enter]ʢ> ͸ೖྗෆཁʣ • > 3+5; 10-3; 2*3;

    100/20 [Enter] • ίʔυ్தͷεϖʔε͸࣮ߦ࣌ʹແࢹ ͞ΕΔ͕ɼίʔυͷΈ΍͢͞ͷͨΊʹ ͋Δఔ౓ۭ͚͓ͯ͘ͱΑ͍ 3. ɹ ͷ جຊૢ࡞
  18. •·ͣ͸ Web ݕࡧ! • seekR: http://seekr.jp/ • R SEEK: http://www.rseek.org/

    • RjpWiki: http://www.okadajp.org/RWiki/ • R-Tips: http://cse.naro.affrc.go.jp/takezawa/r-tips/r.html • ඪ४౥ࡌͷ help(sth) Ͱ΋֬ೝՄೳ 3. ɹ ͷ جຊૢ࡞ ૢ࡞Ͱࠔͬͨ͜ͱ͕͋ͬͨΒ…
  19. •ࢀরࢿྉ͸๛෋ʹ͋Γ·͢ • R ݴޠೖ໳ʢυοτΠϯετʔϧʣ • ͸͡ΊͯͷʮRʯʢྛਅ޿ ࢯʣ • R ʹΑΔ౷ܭॲཧʢ੨໦ൟ৳ઌੜˏ܈അେֶʣ

    • ࠷ۙ͸ॻ੶΋૿͑·ͨ͠ʢͷͰɼ͋ͱ͸ങ࣮ͬͯફ!ʣ 3. ɹ ͷ جຊૢ࡞ ૢ࡞Ͱࠔͬͨ͜ͱ͕͋ͬͨΒ…
  20. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  21. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  22. • R Λշదʹ࢖͏ͨΊͷ౷߹։ൃ؀ڥ (IDE) • ͻͱͭͷը໘ʹෳ਺ͷ৘ใΛ഑ஔʢ࡞ۀޮ཰ UP!ʣ • ͔Ώ͍ͱ͜Ζʹख͕ಧ͘ػೳଟ਺ •

    ؔ਺౳ͷೖྗࢧԉʢtabʣ • ม਺౳ͷத਎Λ͙͢ʹ֬ೝʢCLICK!ʣ • Markdown ʹΑΔϨϙʔτɾεϥΠυ࡞੒ʢׂѪ…ʣ 4. ɹɹɹɹɹɹ ͷ install / update / uninstall
  23. 4. ɹɹɹɹɹɹ ͷ install / update / uninstall https://support.rstudio.com/hc/en-us/articles/200554736-How-To-Uninstall-RStudio •

    Windows 8.1/10 • ίϯύωˠϓϩάϥϜͷΞϯΠϯετʔϧ • ελʔτϝχϡʔ্ͰӈΫϦοΫޙʮΞϯΠϯετʔϧʯ • macOS • /Applications ʹ͋Δ RStudio ΞΠίϯΛΰϛശ΁
  24. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  25. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  26. ը໘ Ͱ͖Δ͜ͱ ΤσΟλʢࠨ্ʣ ؔ਺ͳͲͷೖྗɾطଘεΫϦϓτΛӾཡ "Run" Ͱͦͷ··࣮ߦ΋Մ ίϯιʔϧʢࠨԼʣ ؔ਺ͷ࣮ߦɾม਺΁ͷ୅ೖͳͲ ૉͷ Rʢੜ

    R ʣͱಉ͡ ม਺ɾཤྺʢӈ্ʣ ม਺ͷத਎΍࢖༻ͨؔ͠਺Λදࣔ μϒϧΫϦοΫͰίϯιʔϧʹష෇ ͍Ζ͍ΖʢӈԼʣ ϑΝΠϧͷҰཡදࣔ ࡞ਤ݁Ռͷදࣔ ύοέʔδ؅ཧ ͻͱͭͷը໘Ͱ͢΂ͯͷ͜ͱΛ
  27. 5. ɹɹɹɹɹɹ ͷ جຊૢ࡞ (1) ΤσΟλ • R ίʔυɾίϝϯτΛॻ͘ͱ͜Ζ •

    R ίʔυΛؚΜͩϑΝΠϧͷ৽ن࡞੒ɾอଘ • ίʔυ࣮ߦʹ͸ɼ[Run] Ϙλϯ͔ Ctrl + [Enter] • ίʔυΤϥʔͷࢦఠػೳ΋
  28. 5. ɹɹɹɹɹɹ ͷ جຊૢ࡞ (2) ίϯιʔϧ • R ίʔυͷ࣮ߦɾ݁Ռදࣔ •

    ཤྺ: ্Լ໼ҹΩʔ ɼ͋Δ͍͸ [Ctrl] (Win) / [Command] (Mac) ʴ ্໼ҹΩʔ Ͱ֬ೝ • [Tab] ʹΑΔؔ਺ɾม਺ͷิ׬
  29. 5. ɹɹɹɹɹɹ ͷ جຊૢ࡞ (3) ม਺ɾཤྺ • ม਺ͷத਎ͷ֬ೝ • (1)

    ͷΤσΟλʹදࣔ͞ΕΔ • ϑΟϧλϦϯά΋Մ • History λϒʹͯɼཤྺʢ࣌ܥྻʣͷ֬ೝ • ίϯιʔϧ΁ͷష෇͚΋Մ • μϒϧΫϦοΫͰଈ࣌ʹίϯιʔϧ΁
  30. 5. ɹɹɹɹɹɹ ͷ جຊૢ࡞ (4) ͍Ζ͍Ζ • Files: ࡞ۀσΟϨΫτϦʹ͋ΔϑΝΠϧҰཡ •

    Plots: ࡞ਤ݁ՌͷදࣔɾPDF ౳Ͱͷग़ྗ • Packages: ར༻Մೳͳ Package ͷҰཡ • Help: ؔ਺ͷ࢖͍ํͳͲΛ֬ೝʢͨͩ͠ӳޠʣ • Viewer: HTML ϑΝΠϧ౳ͷදࣔ
  31. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  32. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  33. ม਺ͷ໊લ͸ “hako” •> hako <- c(1,2,3,4,5) •> hako • c()

    ؔ਺ɿcombine ( cf. https://twitter.com/#!/sakaue/status/193708048030760960 ) • ஋Λ̍ͭʹ·ͱΊΔؔ਺ • ٯʹॻ͍ͯ΋ʢҰԠʣOK 6. ؔ਺ͱม਺໋͕
  34. c()ؔ਺ͷ “<-” ͸Կʁ hako <- c(1,2,3,4,5) ͷ “<-” ͸ ࠨ޲͖ͷ໼ҹʢˡʣ

    Λදݱ ʢೖΕସ͑ͯ΋ಈ͖·͢ʣ 6. ؔ਺ͱม਺໋͕
  35. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  36. Agenda 1. R ֓࿦ (15) 2. R ͷ install /

    update / uninstall (15) 3. R ͷجຊૢ࡞ (15) 4. RStudio ͷ install / update / uninstall (15) 5. RStudio ͷجຊૢ࡞ (15) 6. ؔ਺ͱม਺໋͕(15) 7. ԋशʹ͙࣍ԋश (+α)
  37. 7. ԋशʹ͙࣍ԋश 1. R / RStudio Λ࡟আ͠ɼ࠶Πϯετʔϧʢ॓୊ʣ 2. RStudio ͷΞοϓσʔτΛνΣοΫ

    3. 987+789, 654-456, 43*34, 21/12 ͷܭࢉΛҰؾʹ࣮ߦ 4. RStudio ͷཤྺ࿮͔Βίϯιʔϧ΁ίϐʔͯ͠ɼ3 ͷܭࢉ Λ࠶࣮ߦ 5. ม਺ x ʹ 5, ม਺ y ʹ55, ม਺ z ʹ 555 Λ୅ೖ͠ɼ3ͭΛ͔͚ ߹Θͤͨ஋ͷฏํࠜΛؔ਺ͰٻΊΔ ʢ୅ೖҎ֎͸1ߦͰʣ 6. ม਺ v ʹɼ1 ͔Β 20 ·Ͱͷ஋Λ୅ೖ͠ɼ2ͭͷؔ਺Λ༻͍ ͯฏۉ஋Λࢉग़ʢsummary ؔ਺ɾmean ؔ਺Λ࢖Θͣʹʣ ʢ2ݶ࣋ͪӽ͠΋ʣ
  38. 7. ԋशʹ͙࣍ԋशʢώϯτʣ 1. ʮR/RStudio ΞϯΠϯετʔϧʯ౳Ͱ Web ݕࡧʢ॓୊ʣ 2. ʮRStudio ΞοϓσʔτʯͰ

    Web ݕࡧ 3. ηϛίϩϯ͕େࣄͰ͢ 4. ཤྺ࿮ͰඞཁͳίʔυΛμϒϧΫϦοΫ 5. ฏํࠜΛٻΊΔؔ਺ͷҾ਺ʹ x, y, z Λ࢖ͬͨࣜΛೖΕΔ 6. ߹ܭ஋Λग़ؔ͢਺ʗσʔλͷݸ਺ΛٻΊΔؔ਺ ʢ2ݶ࣋ͪӽ͠΋ʣ