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

RBC202003_Day2_Period5

sakaue
March 20, 2020

 RBC202003_Day2_Period5

sakaue

March 20, 2020
Tweet

More Decks by sakaue

Other Decks in Education

Transcript

  1. 1. σʔλͷཁ໿ͷඞཁੑ • σʔλΛूΊ͚ͨͩͰ͸Կ΋൑அͰ͖ͳ͍ • σʔλΛཁ໿ʢ਺஋ཁ໿ʣΛ͢Δ͜ͱͰɼશମ͕ Ͳ͏ͳ͍ͬͯͯɼ෼෍΍͹Β͖͕ͭͲ͏ͳ͍ͬͯ Δ͔͕೺ѲͰ͖Δ • தؒςετͰऔͬͨ55఺͸ྑ͍఺ʁɼѱ͍఺ʁ

    • ظ຤ςετͷฏۉ఺͕80఺ͷ৔߹ɼશମతʹྑ͍Ͱ͖͙͍͋ʁ • ฏۉɾ͹Β͖ͭʢSDʣʹΑΔʢ͠ɼςετ໰୊ͷ಺༰΍ ഑఺ʹΑΔʢ͠ɼԿΛ͔֬Ί͍͔ͨʹΑΔʣʣ
  2. • sum() ؔ਺ • x <- c(1, 2, 3, 4,

    5) • sum(x) • sum(x[2 : 4]) • ϕΫτϧͷ2൪໨͔Β4൪໨ͷཁૉͷ૯࿨ • y <- c(1:1000) • sum(y) • sum(y[27:89]) 2. ϕΫτϧΛ࢖ͬͨ਺஋ཁ໿
  3. • mean() ؔ਺: ฏۉ஋ΛٻΊΔ • ฏۉ஋: σʔλͷ૯࿨Λσʔλͷݸ਺Ͱׂͬͨ஋ • mean(x); mean(y)

    • median() ؔ਺: தԝ஋ΛٻΊΔ • தԝ஋: খ͍͞ॱʹฒ΂ͨ࣌ʹਅΜதͷॱҐʹ͘Δ஋ • median(x); median(y) • ฏۉ஋ͷ᠘ • ۃ୺ͳ஋͕ࠞ͟ΔͱӨڹΛड͚ͯ͠·͏ • a <- c(100, 200, 300, 400, 500) • mean(a); median(a) • b <- c(100, 200, 300, 400, 5000) • mean(b); median(b) 2. ϕΫτϧΛ࢖ͬͨ਺஋ཁ໿
  4. • max() ؔ਺: ࠷େ஋ΛٻΊΔ • min() ؔ਺: ࠷খ஋ΛٻΊΔ • var()

    ؔ਺: ෼ࢄΛٻΊΔ • sd() ؔ਺: ඪ४ภࠩΛٻΊΔ • summary() ؔ਺: ཁ໿౷ܭྔΛҰ౓ʹٻΊΔ • ࠷খ஋, தԝ஋, ฏۉ஋, ࠷େ஋, Լଆ25%఺, ্ଆ25%఺ • max(x); max(y) • min(x); min(y) • var(x);var(y) • sd(x); sd(y) • summary(x); summary(y) 2. ϕΫτϧΛ࢖ͬͨ਺஋ཁ໿
  5. 3. ߦྻΛ࢖ͬͨ਺஋ཁ໿ • ѻ͍ํ͸ϕΫτϧͷ਺஋ཁ໿ͱಉ͡ • matrix.4 <- matrix(c(1, 2, 3,

    4, 5, 6, 7, 8, 9), nrow = 3, ncol = 3, byrow = TRUE) • matrix.4 Ͱத਎Λ֬ೝ • sum(matrix.4) #ߦྻʹ͋Δ஋ͷ૯࿨ • mean(matrix.4) #ߦྻશମͷฏۉ஋ • sum(matrix.4[1,]) #ߦྻ1ߦ໨ͷ૯࿨ • mean(matrix.4[,2:3]) #ߦྻ2-3ྻ໨ͷฏۉ஋
  6. 3. ߦྻΛ࢖ͬͨ਺஋ཁ໿ • ͪΐͬͱ஋ɾཁૉ਺Λେ͖ͯ͘͠Έ·͠ΐ͏ • matrix.5 <- matrix(c(1:5000), nrow =

    100, ncol = 50, byrow = TRUE) • matrix.5 Ͱத਎Λ֬ೝ • sum(matrix.5) #ߦྻʹ͋Δ஋ͷ૯࿨ • mean(matrix.5) #ߦྻશମͷฏۉ஋
  7. 3. ߦྻΛ࢖ͬͨ਺஋ཁ໿ • rowSums() ؔ਺; colSums() ؔ਺; • ߦ͝ͱྻ͝ͱʹ૯࿨ΛٻΊΔؔ਺ •

    rowSums(matrix.4); rowSums(matrix.5) • colSums(matrix.4); colSums(matrix.5) • rowMeans () ؔ਺; colMeans() ؔ਺ • ߦ͝ͱྻ͝ͱʹฏۉ஋ΛٻΊΔؔ਺ • rowMeans(matrix.4); rowMeans(matrix.5) • colMeans(matrix.4); colMeans(matrix.5)
  8. 3. ߦྻΛ࢖ͬͨ਺஋ཁ໿ • apply() ؔ਺ • ߦ͝ͱྻ͝ͱʹ༷ʑͳؔ਺Λద༻ • apply(ߦྻ໊, Ϛʔδϯ,

    ద༻͢Δؔ਺ʣ • Ϛʔδϯ͕1ͳΒߦ͝ͱɼ2ͳΒྻ͝ͱ • apply(matrix.4, 1, sum) #ߦ͝ͱͷ૯࿨ • rowSums(matrix.4) ͱಉ͡ॲཧ • apply(matrix.4, 2, mean) #ྻ͝ͱͷฏۉ • colMeans(matrix.4) ͱಉ͡ॲཧ
  9. 3. ߦྻΛ࢖ͬͨ਺஋ཁ໿ • apply() ؔ਺ͷଓ͖ • apply(matrix.4, 1, max) •

    #ߦ͝ͱͷ࠷େ஋ • apply(matrix.4, 2, summary) • #ྻ͝ͱͷཁ໿౷ܭྔ
  10. 2. 1͔Β10000·Ͱͷ஋͕ೖͬͨߦྻʢ100ߦɾ100ྻʣΛ࡞੒ͯ͠… 1. 20ߦ໨ʮͱʯ70ߦ໨ͷ2ߦͷΈͷ֤૯࿨ΛٻΊΔ 2. 31ྻ໨ʮ͔Βʯ80ྻ໨·Ͱͷ50ྻͷ֤ฏۉ஋ΛٻΊΔ 3. ߦ͝ͱɾྻ͝ͱͷ૯࿨ΛٻΊΔʢapply ؔ਺Λ࢖༻ʣ 4.

    ߦ͝ͱɾྻ͝ͱͷฏۉ஋ΛٻΊΔʢapply ؔ਺Λ࢖༻ʣ 5. ߦ͝ͱɾྻ͝ͱͷཁ໿౷ܭྔΛٻΊΔʢapply ؔ਺Λ࢖༻ʣ 6. psych ύοέʔδΛ࢖ͬͯཁ໿౷ܭྔΛٻΊΔ • ೚ҙͷߦɾྻʹରͯ͠ٻΊͯΈΔ 4. ԋशʹ͙࣍ԋश
  11. 2. matrix() ؔ਺Λ࢖͍ɼྻ਺ͷࢦఆͱ byrow ͷઃఆʹ༻৺ 1. ߦͷෳ਺ࢦఆ͸ c() ؔ਺Λ࢖͍·͠ΐ͏ 2.

    ྻͷൣғࢦఆ͸ίϩϯΛ࢖͍·͠ΐ͏ 3. apply() ؔ਺ͱ sum() ؔ਺Λ૊Έ߹Θͤ·͠ΐ͏ 4. apply() ؔ਺ͱ mean() ؔ਺Λ૊Έ߹Θͤ·͠ΐ͏ 5. apply() ؔ਺ͷߦͱྻͷࢦఆ͸ɼ1 ͔ 2 Ͱ෼͚·͢ 6. ·ͣ͸ install.packages() ͯ͠ library() Ͱ༗ޮԽ 4. ԋशʹ͙࣍ԋशʢώϯτʣ