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

RBC202003_Day2_Period6

sakaue
March 20, 2020

 RBC202003_Day2_Period6

sakaue

March 20, 2020
Tweet

More Decks by sakaue

Other Decks in Education

Transcript

  1. Agenda 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ (10) 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ

    (10) 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ (20) 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ (20) 5. ԋशʹ͙࣍ԋश (30)
  2. Agenda 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ (10) 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ

    (10) 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ (20) 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ (20) 5. ԋशʹ͙࣍ԋश (30)
  3. • WindowsɿϑΝΠϧ → σΟϨΫτϦͷมߋ • “My Documents” ʹϑΝΠϧҠಈ • Mac

    OS Xɿ؀ڥઃఆ → Ұൠʢىಈʣ • ϗʔϜσΟϨΫτϦʹϑΝΠϧҠಈ • Linuxɿup to you... 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ
  4. Agenda 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ (10) 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ

    (10) 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ (20) 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ (20) 5. ԋशʹ͙࣍ԋश (30)
  5. Agenda 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ (10) 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ

    (10) 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ (20) 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ (20) 5. ԋशʹ͙࣍ԋश (30)
  6. 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ • ॲཧ༻σʔλ͸ܰΊͷ CSV /

    TXT ܗ͕ࣜΦεεϝ • ಡΈࠐΈ଎౓ɼϝϞϦ΁ͷෛՙʹӨڹ • ๭ Excel Ͱ͸ɼCSV Ͱͷॻ͖ग़͠ʹରԠ • ݴޠσʔλͰ͋Ε͹ɼTXT ϑΝΠϧ͕ແ೉
  7. 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ • CSV (Comma Separated

    Value) ϑΝΠϧͷྫ • data01.csv ͷத਎Λ֬ೝ • ๭ Excel Ͱ։͔Εͯ͠·͏͜ͱ΋͋ΔͷͰ༻৺ of,29391 in,18214 to,9343 for,8412 with,6575
  8. 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ • TXT ϑΝΠϧͷྫ •

    data05.txt ͷத਎Λ֬ೝ • miʢMacʣɾαΫϥΤσΟλʢWinʣ ౳ͷςΩετΤσΟλ Ͱ։͘͜ͱ͕๬·͍͠ʢվߦίʔυɾจࣈίʔυͷ֬ೝʣ R is a free software environment for statistical computing and graphics. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS. To download R, please choose your preferred CRAN mirror. If you have questions about R like how to download and install the software, or what the license terms are, please read our answers to frequently asked questions before you send an email.
  9. 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ • data01.csv ͱ data05.txt

    ͷத਎Λ֬ೝͯ͠ΈΔ 1. miʢMacʣɾαΫϥΤσΟλʢWinʣ Λμ΢ϯϩʔυ͠ ͯΠϯετʔϧ 2. https://sites.google.com/site/yasatekir/͔ΒඞཁͳϑΝ ΠϧΛμ΢ϯϩʔυ 3. ֤ΞϓϦέʔγϣϯΛىಈ͢Δ 4. File -> Open ͷΑ͏ͳखॱͰμ΢ϯϩʔυͨ͠΋ͷΛ։ ͍ͯத਎Λ֬ೝ͢Δʢ௨ৗɼDownload ϑΥϧμʣ 5. จࣈίʔυ΍վߦίʔυΛ֬ೝ͢Δ
  10. Agenda 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ (10) 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ

    (10) 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ (20) 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ (20) 5. ԋशʹ͙࣍ԋश (30)
  11. Agenda 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ (10) 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ

    (10) 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ (20) 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ (20) 5. ԋशʹ͙࣍ԋश (30)
  12. 1. data01.csv Λ࡞ۀσΟϨΫτϦ΁Ҡಈ • XLS/XLSX ܗࣜͷ΋ͷ͸อଘ࣌ʹม׵ • CSV ϑΝΠϧͷจࣈίʔυ͸ UTF-8

    ʹ 2. σʔλʢheader ͳ͠ʣΛಡΈࠐΉ 1. > data01 <- read.csv("data01.csv", header=FALSE) 2. > data01 <- read.csv(file.choose(), header = FALSE) 1. ࡞ۀσΟϨΫτϦʹೖ͍ͬͯΕ͹ɼϑΝΠϧ໊Λ ೖྗ͢ΔͷΈͰΑ͍ʢύε΁ͷҙࣝ͸ෆཁʣ 2. ࡞ۀσΟϨΫτϦҎ֎ʹஔ͍͍ͯΔ৔߹͸ɼ file.choose() ؔ਺Λ૊Έ߹Θͤͯࣗ෼ͰબͿ 3. > data01 [Enter] Ͱத਎Λ֬ೝ 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ
  13. 1. data02.csv Λ࡞ۀσΟϨΫτϦ΁Ҡಈ 2. data02.csv ͷத਎ΛςΩετΤσΟλͰ֬ೝ 3. σʔλʢheader ͋ΓʣΛಡΈࠐΉ 1.

    > data02 <- read.csv(file.choose(), header = TRUE) • file.choose() ͸ศར͕ͩɼͲͷϑΝΠϧΛ࢖ͬͨ ͔͕ɼཤྺΛݟ௚ͯ͠΋෼͔Βͳ͍ͷͰ༻৺ 4. > data02 [Enter] Ͱத਎Λ֬ೝ 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ
  14. 1. data03.csv Λ࡞ۀσΟϨΫτϦ΁Ҡಈ 2. data03.csv ͷத਎ΛςΩετΤσΟλͰ֬ೝ 3. σʔλʢ๯಄ϝϞ͋Γɼheader ͋ΓʣΛಡΈࠐΉ •

    > data03 <- read.csv(file.choose(), header = TRUE, skip =2) • Ҿ਺ skip ʹΑΓɼ๯಄ n ߦ໨Λඈ͹ͯ͠ಡࠐ 4. > data03 [Enter] Ͱத਎Λ֬ೝ 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ
  15. 1. data04.csv Λ࡞ۀσΟϨΫτϦ΁Ҡಈ 2. data04.csv ͷத਎ΛςΩετΤσΟλͰ֬ೝ 3. σʔλʢߦɾྻϥϕϧ͋ΓʣΛಡΈࠐΉ • >

    data04 <- read.csv(file.choose(), header = TRUE, row.names =1) • Ҿ਺ row.names ʹΑΓɼߦϥϕϧ͋ΓΛࢦఆ 4. > data04 [Enter] Ͱத਎Λ֬ೝ 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ
  16. 1. data05.txt Λ࡞ۀσΟϨΫτϦ΁Ҡಈ 2. data05.txt ͷத਎ΛςΩετΤσΟλͰ֬ೝ 3. σʔλʢ̍ϨίʔυͣͭʣΛಡΈࠐΉ • >

    data05 <- scan(file.choose(), what = "char", sep = "\n", quiet = TRUE) • scan() ؔ਺ͰςΩετσʔλͷಡΈࠐΈ • Ҿ਺ what Ͱσʔλܕͱͯ͠ʮจࣈྻʯΛࢦఆ • Ҿ਺ sep Ͱ۠੾ΓΛࢦఆ͠ɼࠓճ͸̍Ϩίʔυ • sep Λࢦఆ͠ͳ͍ͱɼۭന۠੾ΓͰಡࠐ • quiet ͸σʔλͷݸ਺Λදࣔ͞Εͳ͍ͨΊͷ΋ͷ 4. > data05 [Enter] Ͱத਎Λ֬ೝ 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ
  17. Agenda 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ (10) 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ

    (10) 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ (20) 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ (20) 5. ԋशʹ͙࣍ԋश (30)
  18. Agenda 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ (10) 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ

    (10) 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ (20) 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ (20) 5. ԋशʹ͙࣍ԋश (30)
  19. • جຊૢ࡞͸ Local PC ฤͱಉ͡ • σʔλͷ Upload ͷΈࡁ·͓ͤͯ͘ •

    ֤छσʔλ͸ɼUpload લʹจࣈίʔυΛ UTF-8 ͱ ͓ͯ͘͠ͷ͕ແ೉ • ZIP ϑΝΠϧͷ৔߹͸ࣗಈల։͞ΕΔ • ϑΝΠϧ͸࡞ۀσΟϨΫτϦ௚ԼʹҠಈ͓ͤͯ͘͞ • ౰֘σΟϨΫτϦʹҠಈޙɼMore -> Move ͰҠಈ 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ
  20. 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ 1. https://sites.google.com/site/yasatekir/͔Β ZIP ϑΝ ΠϧʢUTF-8ʣΛμ΢ϯϩʔυ

    2. RStudio Server ্ͰɼUpload ϘλϯΛԡ͠ɼ"ZIP ͷ ··Ͱ" ૹ৴ʢల։͠ͳ͍ʣ 3. ֤ϑΝΠϧΛ࡞ۀσΟϨΫτϦҎԼʹҠಈʢMoveʣ 4. ֤ϑΝΠϧͷ಺༰Λ֬ೝ͠ɼLocal Ͱ࣮ߦͨ͠ίʔυ Λ࠶࣮ߦ
  21. Agenda 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ (10) 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ

    (10) 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ (20) 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ (20) 5. ԋशʹ͙࣍ԋश (30)
  22. Agenda 1. ࡞ۀσΟϨΫτϦͷઃఆ֬ೝ (10) 2. ॲཧ༻σʔλ͸ CSV ͔ TXT ܗࣜͰ

    (10) 3. ϑΝΠϧͷಡΈࠐΈ: Local PC ฤ (20) 4. ϑΝΠϧͷಡΈࠐΈ: RStudio Server ฤ (20) 5. ԋशʹ͙࣍ԋश (30)
  23. 5. ԋशʹ͙࣍ԋश 1. Local PC ʹ͋Δ data05.txt Λ࢖͍… 1. RStudio

    Server ʹΞοϓϩʔυʢ஫: ࡞ۀσΟϨΫτϦ௚Լʣ 2. RStudio Server Ͱͷ࡞ۀσΟϨΫτϦΛ֬ೝ 3. data05.txt ΛಡΈࠐΈʢ1Ϩίʔυ୯ҐͰಡΈࠐΈʣ 4. ཁૉ਺Λ਺͑Δ 5. શମͷ߹ܭจࣈ਺Λ਺͑Δ 6. ୯ޠʹ෼ׂ͠ɼ૯ޠ਺Λ਺͑Δʢ1ߦͰॻ͘ʣ 7. ̍୯ޠ͋ͨΓͷฏۉจࣈྻ਺ΛٻΊΔʢແཧ΍Γ1ߦͰॻ͘ʣ
  24. 5. ԋशʹ͙࣍ԋशʢώϯτʣ 1. Local PC ʹ͋Δ data05.txt Λ࢖͍… 1. ·ͣ

    Upload ϘλϯΛԡ͠·͠ΐ͏ 2. getwd() ؔ਺Λ࢖͍·͢ 3. TXT ϑΝΠϧͷಡΈࠐΈʹ࢖͏ؔ਺Λ୳͠·͠ΐ͏ 4. ୈ4ݶͷࢿྉΛݟ௚ͯ͠Έ·͠ΐ͏ 5. ୈ4ݶͷࢿྉΛݟ௚ͯ͠Έ·͠ΐ͏ 6. ୈ4ݶͷࢿྉΛݟ௚ͯ͠Έ·͠ΐ͏ 7. ฏۉจࣈྻʹ૯จࣈ਺ʗ૯୯ޠ਺