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

RBC202003_Day1_Period4

sakaue
March 19, 2020

 RBC202003_Day1_Period4

sakaue

March 19, 2020
Tweet

More Decks by sakaue

Other Decks in Education

Transcript

  1. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  2. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  3. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  4. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  5. • จࣈྻΛม਺ʹ୅ೖ • str.1 <- "cats" • จࣈྻϕΫτϧͷ࡞੒ • str.2

    <- c("I", "love", "cats.") • str.3 <- c("ࢲ͸ωί͕޷͖Ͱ͢ɻ") • ೋॏҾ༻ූͱΧϯϚʹ༻৺ 2. จࣈྻͷ୅ೖͱσʔλܕ
  6. • ਺஋Λ਺஋ͱͯ͠୅ೖ • num <- c(1, 2, 3) • ਺஋Λ਺ࣈʢจࣈྻʣͱͯ͠୅ೖ

    • str.4 <- c("1", "2", "3") • ग़ྗ݁Ռͷҧ͍Λ֬ೝ 2. จࣈྻͷ୅ೖͱσʔλܕ
  7. • σʔλܕʢclassʣͷҧ͍ • ਺஋ͱͯ͠ѻ͏͔จࣈͱͯ͠ѻ͏͔ • class ؔ਺Ͱ൑ఆ • class(num) •

    class(str.4) • numeric ͔ character ͔Λ֬ೝ 2. จࣈྻͷ୅ೖͱσʔλܕ
  8. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  9. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  10. • paste() ؔ਺ • จࣈྻΛ݁߹͢Δؔ਺ • paste("William", "Shakespeare") • paste("Ն໨",

    "ᕸੴ") • paste("Ն໨", "ᕸੴ", sep = "") 3. จࣈྻॲཧ޲͚ͷؔ਺
  11. • จࣈྻͷೖͬͨม਺Λ݁߹ • Kawabata <- "઒୺" • Yasunari <- "߁੒"

    • paste(Kawabata, Yasunari) • ࿈൪ͷ෇͍ͨม਺Λੜ੒ • paste("No.", 1 : 500, sep="") 3. จࣈྻॲཧ޲͚ͷؔ਺
  12. • nchar() ؔ਺ • σʔλͷจࣈ਺Λ਺͑Δؔ਺ • nchar("cat") • nchar("ೣ") •

    nchar(c("I", "love", "cats.")) • nchar(c("ࢲ", "͸", "ೣ", "͕", "޷͖", "Ͱ͢ɻ")) 3. จࣈྻॲཧ޲͚ͷؔ਺
  13. • ฏۉจࣈ਺ͳͲΛٻΊΔ • word.length <- nchar(c("I", "love", "cats.")) • mean(word.length)

    • table(word.length) • mean() ؔ਺: ฏۉ஋ΛٻΊΔ • table() ؔ਺: ౓਺෼෍දΛ࡞੒ 3. จࣈྻॲཧ޲͚ͷؔ਺
  14. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  15. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  16. • substr() ؔ਺: จࣈྻ͔Β೚ҙͷ෦෼Λൈ͖ग़͢ • substr("ABCDE", start =1, stop=3) •

    1จࣈ໨͔Β3จࣈ໨Λநग़ • substr("͍͋͏͓͑", start =2, stop=4) • 2จࣈ໨͔Β4จࣈ໨Λநग़ 4. จࣈྻͷݕࡧͱஔ׵
  17. • grep() ؔ਺: จࣈྻΛݕࡧ͠දࣔ͢Δ • verbs <- c("asked", "had", "looked",

    "took") • ϕΫτϧ verbs Λ࡞੒͠4୯ޠΛ୅ೖ • verbs.n <- grep("ed", verbs) • ϕΫτϧ verbs ͔Β ed ΛؚΉ΋ͷΛநग़ • verbs.n ʹ͸ɼநग़͞Εͨཁૉͷ൪߸ ʢ਺஋ʣͷϕΫτϧ͕୅ೖ͞Ε͍ͯΔ • verbs[verbs.n] • ཁૉͷ൪߸ʹ֘౰͢Δ୯ޠΛදࣔ 4. จࣈྻͷݕࡧͱஔ׵
  18. • grep() ؔ਺ͷҾ਺ perl: Perl ͷਖ਼نදݱΛར༻ • words <- c("asked",

    "edited", "edition", "education", "looked") • words.n <- grep("ed", words) • words [words.n] • words.n.2 <- grep("ed$", words, perl =TRUE) • ed ͰʮऴΘΔʯจࣈྻΛݕࡧ • words[words.n.2] • words.n.3 <- grep("^ed", words, perl =TRUE) • ed Ͱʮ࢝·ΔʯจࣈྻΛݕࡧ • words[words.n.3] 4. จࣈྻͷݕࡧͱஔ׵
  19. • gsub() ؔ਺: จࣈྻΛஔ׵͢Δ • words.2 <- c("asked", "looked", "walked")

    • gsub("ed$", "s", words.2, perl=TRUE) • ֤จࣈྻͷ຤ʹ͋Δ ed Λ s ʹஔ׵ • adverbs <- c("ඒ͘͠", "ߴ͘", "଎͘") • gsub("͘$", "͍", adverbs, perl=TRUE) • ֤จࣈྻͷ຤ʹ͋Δ "͘" Λ "͍" ʹஔ׵ 4. จࣈྻͷݕࡧͱஔ׵
  20. • gsub() ؔ਺ʹΑΔจࣈྻͷ࡟আ • nouns <- c("birds", "cats", "dogs") •

    gsub("s$", "", nouns, perl=TRUE) • ֤จࣈྻͷ຤ʹ͋Δ "s" Λ࡟আ • Կ΋ͳ͍΋ͷʮ""ʯʹஔ׵ʹ࡟আ • ୯ޠͷ੔ܗͳͲʹར༻ʢޠ਺Χ΢ϯτʣ 4. จࣈྻͷݕࡧͱஔ׵
  21. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  22. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  23. • strsplit() ؔ਺: จࣈྻͷ෼ׂ • and <- c("black and white",

    "bread and butter", "cats and dogs") • strsplit(and, split = " and ") • Ҿ਺ split ʹΑΓ۠੾ΓΛࢦఆ • " and " Λ۠੾Γͱͯ͠෼ׂ • unlist() ؔ਺: ϦετܗࣜͷσʔλΛϕΫτϧԽ • unlist(strsplit(and, split = " and ")) • ݟ͑ͳ͍࠯Ͱͭͳ͕ΕͨཁૉΛόϥόϥʹ͢ΔΠϝʔδ 5. จࣈྻͷ෼ׂ
  24. • ӳจΛ୯ޠʹ෼ׂ͢Δ • ulysses <- "Stately, plump Buck Mulligan came

    from the stairhead, bearing a bowl of lather on which a mirror and a razor lay crossed." • unlist(strsplit(ulysses, split = " ")) • εϖʔεΛ۠੾Γͱͨ͠෼ׂ • ΧϯϚ΍ϐϦΦυɼ׆༻ܗͷॲཧʹ༻৺ 5. จࣈྻͷ෼ׂ
  25. • ೔ຊޠͷจΛ1จࣈͣͭ෼ׂ͢Δ • souri <- “෯޿͘ื͍ͬͯΔͱ͍͏ೝࣝͰɺ ืू͍ͯ͠Δͱ͍͏ೝࣝͰ͸ͳ͔ͬͨɻ” • unlist(strsplit(souri, split

    = “")) • จࣈ਺Χ΢ϯτ͸͜Ε͕جຊ • ࣮ࡍʹ͸ܗଶૉղੳͳͲͷલॲཧΛ࣮ߦ 5. จࣈྻͷ෼ׂ
  26. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  27. Agenda 1. ݴޠσʔλॲཧͰ R Λ࢖͏ҙٛ (5) 2. จࣈྻͷ୅ೖͱσʔλܕ (15) 3.

    จࣈྻॲཧ޲͚ͷؔ਺ (15) 4. จࣈྻͷݕࡧͱஔ׵ (20) 5. จࣈྻͷ෼ׂ (15) 6. ԋशʹ͙࣍ԋश (20)
  28. 1. DONE IS BETTER THAN PERFECT ͱ͍͏ӳจͰ1ͭͷϕΫτϧ Λ࡞੒্ͨ͠Ͱ 1. େจࣈΛখจࣈʹ͢Δ

    2. େจࣈΛখจࣈʹ͔ͯ͠Β·ͨେจࣈʹ໭͢ 3. େจࣈΛখจࣈʹͯ͠ɼେจࣈʹ໭͔ͯ͠Β΍ͬͺΓ খจࣈʹ͢Δ 4. ཁૉ਺Λ਺͑Δ 5. จࣈ਺Λ਺͑Δ 6. ୯ޠʹ෼্ׂͨ͠Ͱޠ਺Λ਺͑Δ 6. ԋशʹ͙࣍ԋश
  29. 1. DONE IS BETTER THAN PERFECT ͱ͍͏ӳจͰ1ͭͷϕΫτϧ Λ࡞੒্ͨ͠Ͱ 1. ʮେจࣈɹখจࣈɹRɹؔ਺ʯͰ

    Web ݕࡧ 2. ʮೖΕࢠߏ଄ʯΛ࢖ͬͯΈ·͠ΐ͏ 3. ʮೖΕࢠߏ଄ʯΛ࢖ͬͯΈ·͠ΐ͏ 4. length() ؔ਺Ͱ਺͑·͠ΐ͏ 5. nchar() ؔ਺Ͱ਺͑·͠ΐ͏ 6. ෼ׂʹ͸ strsplit() ؔ਺ͱ unlist() ؔ਺Λ࢖͍ɼ਺͑Δͷ ͸্ͷؔ਺ͷͲΕ͔Λ࢖͍·͢ 6. ԋशʹ͙࣍ԋशʢώϯτʣ
  30. 2. No one wants to die. Even people who want

    to go to heaven don't want to die to get there. ͱ͍͏2ͭͷ ӳจΛผཁૉͯ͠ѻ͍ɼ͔ͭɼ1ͭͷϕΫτϧΛ࡞ ੒্ͨ͠Ͱ 1. ཁૉ਺Λ਺͑Δ 2. จࣈ਺Λ਺͑Δ 3. ୯ޠʹ෼ׂ͠ɼ2จ߹ܭͷޠ਺Λ਺͑Δʢ1ߦͰʣ 4. 1จ͋ͨΓͷฏۉ୯ޠ਺ΛٻΊΔʢ͋͑ͯ1ߦͰʣ 6. ԋशʹ͙࣍ԋश