R Object

R Object

What's R object.

8cf15712e8fbabc8c619ed4e823b7a80?s=128

Itoshi NIKAIDO

September 06, 2012
Tweet

Transcript

  1. 3ͷΦϒδΣΫτ *UPTIJ/*,"*%0ESJUPTIJ!HNBJMDPN 1

  2. 3͸͢΂͕ͯΦϒδΣΫτ WFDUPS NBUSJY ؔ਺ ͻͱͭͷΫϥεʹଐ͢Δ 2

  3. ͦ΋ͦ΋ΦϒδΣΫτͱ͸ ม਺΍γϯϘϧΛհͯ͠ϝϞϦͷσʔλ΁ΞΫηε͍ͨ͠ ݴޠ͔Β௚઀ϝϞϦʹΞΫηε͢Δͱ͍Ζ͍Ζͱ໘౗ ಛผͳσʔλߏ଄ΛܾΊ͓͖ͯΦϒδΣΫτͱͯ͠ఆ͓ٛͯ͘͠ ͦͷΦϒδΣΫτʹγϯϘϧ΍ม਺Λհͯ͠ΞΫηε͢Ε͹ָ 3

  4. 3ΦϒδΣΫτʹ͸σʔλܕ͕͋Δ JOUFHFS EPVCMF MPHJDBM DPNQMFY DIBSBDUFS SBX 4

  5. ͋Ε OVNFSJD͸ 3ΦϒδΣΫτʹ͸σʔλܕҎ֎ͷ֓೦͕͋ΔˠNPEF 5

  6. NPEF 4͸σʔλܕΛNPEFͱݺΜͰ͍ͨΒ͍͠ 4ͱͷޓ׵ͷͨΊɻNPEF͕͋Δ type mode logical logical integer numeric double

    numeric complex complex character character Ϣʔβ͕ҙࣝ͢Δ ͷ͸͜͜ 6
  7. type mode storage mode logical logical logical integer numeric integer

    double numeric double complex complex complex character character character TUPSBHFNPEF ϝϞϦ্Ͱ͸ͲͷΑ͏ͳσʔλܕͰอଘ͍ͯ͠Δͷ͔ ϝϞϦ্Ͱ͸OVNFSJDΛ۠ผ͠ͳ͚Ε͹ͳΒͳ͍ typeof() mode() storage.mode() ΄͔ͷݴޠ͔Β σʔλʹΞΫη ε͢Δ৔߹͸ε τϨʔδϞʔυ ͕ॏཁʹͳΔ 7
  8. ΦϒδΣΫτ͸ଐੑΛ࣋ͭ ੒෼ͷ໊લɺ࣍ݩɺॴଐ͢ΔΫϥεɺ࣌ܥྻଐੑ 8

  9. ΦϒδΣΫτ͸ଐੑΛ࣋ͭ ੒෼ͷ໊લɺ࣍ݩɺॴଐ͢ΔΫϥεɺ࣌ܥྻଐੑͳͲ names() dimnames() dim() class() tsp() ΦϒδΣΫτͷߏ଄: str() ΦϒδΣΫτͷଐੑ:

    attributes() 9
  10. ΦϒδΣΫτ͸σʔλߏ଄Λදݱ͢Δ ΦϒδΣΫτΛͻͱ·ͱ·Γʹͯ͠ɺ·ͱΊͯૢ࡞͍ͨ͠ WFDUPS NBUSJY MJTU EBUBGSBNF 10

  11. ࣍ݩ਺ͱҟͳΔλΠϓΛࠞͥΒΕΔ͔Ͱ෼ྨͰ͖Δ 3ͰجຊͱͳΔͭͷσʔλߏ଄ 3 2 4 1 vector 1D 2D same

    types differential types ... 3 2 4 1 matrix ... 2 0 5 3 1 1 7 3 ... 3 A 4 G ... 3 A 4 C ... 2 T 5 G 1 G 7 C ... data frame list c(3,2,4,1) list(3,”A”,4,”G”) matrix( c(3,2,1,2,0,1,4,5,7,1,3,3), nrow = 3 ) data.frame( first = c(3,2,1), first.base = c("A", "T", "G"), second = c(4,5,7), second.base = c("C", "G", "C") ) 11
  12. ΧςΰϦΧϧม਺Λදݱ͢ΔͨΊͷσʔλߏ଄ ౷ܭݴޠΒ͍͠σʔλߏ଄GBDUPS உঁɺ೥୅ɺΫϥε෼͚ͳͲΧςΰϦΛѻ͍͍ͨ ͜ͷਫ४ʹจࣈྻͷ໊લΛ࢖͍͍ͨ ਫ४Λ਺஋Ͱදݱͯ͠͠·͏ͱɺޡͬͯ਺஋ܭࢉͯ͠͠·͏ڪΕ͕͋Δ ಛผͳਫ४Λදݱ͢Δσʔλߏ଄ͱͯ͠ factor ͕༻ҙ͞Ε͍ͯΔ 12

  13. factor class Ͱ͋Γɺlabels ଐੑΛ࣋ͭΦϒδΣΫτ GBDUPSͷߏ଄ R> sex <- factor(c("female", "male",

    "female", "female")) R> sex [1] female male female female Levels: female male ## level ਺ R> nlevels(sex) [1] 2 R> is(sex) [1] "factor" "integer" "oldClass" "numeric" "vector" R> class(sex) [1] "factor" R> str(sex) Factor w/ 2 levels "female","male": 1 2 1 1 ಺෦తʹ͸ϥϕϧ͕੔਺ʹׂΓ౰ͯΒΕ͍ͯΔ 13
  14. ͍ͭͷ·ʹ͔ factor ʹͳΔɻfactor ͷͳʹ͕خ͍͔͠ GBDUPS͕ۤख > R ͸ character Λ

    factor ΁ڧ੍ม׵͕ͨ͠Δ - σʔλϑϨʔϜʹม׵ͨ͠ͱ͖ data.frame(stringsAsFactors = default.stringsAsFactors) - ςΩετϑΝΠϧ͔ΒσʔλΛೖྗͨ͠ͱ͖ read.table(stringsAsFactors = TRUE) > Factor ʹ׳Εͨ΄͏͕خ͍͜͠ͱ͕ͨ͘͞Μ͋Δ ؔ਺΍Ϟσϧ͕ࣜ factor ΛΧςΰϦΧϧม਺ͱͯ͠ೝࣝͯ͠ Α͍۩߹ʹॲཧͯ͘͠ΕΔ 14
  15. ΦϒδΣΫτࢦ޲ϓϩάϥϛϯά ࣗ෼ͰΦϒδΣΫτΛఆ͍ٛͨ͠ R ͷΦϒδΣΫτࢦ޲͸ྺ࢙తܦҢͰ3छྨ΋͋Δ... ͜Ε͔Β֮͑ΔͳΒR5͚֮ͩ͑Ε͹Α͍ (͘͢͝ࢲݟ) - S3: ΦϒδΣΫτͷଐੑʹΫϥε໊ΛೖΕ͚ͨͩ +

    ૯শؔ਺ɻ ΏΔ;Θɻ - S4:Ϋϥε΍ϝιουΛݫີʹఆٛͰ͖ΔΑ͏ʹͳͬͨ! Ͱ΋஋౉͠... ࠇྺ࢙ͳͷͰɺBioconductor ͷύοέʔδ࡞Βͳ͍ਓ͸ ๨ΕͯΑ͍ (·ͨࢲݟ) - R5: ͍ΘΏΔී௨ͷΦϒδΣΫτࢦ޲ (R2.12Ҏ߱) ΦϒδΣΫτΛࢀর౉͠Ͱ͖Δ! ΦϒδΣΫτ࡞੒ޙʹมߋͰ͖Δ = mutable ͳΦϒδΣΫτ ී௨ͷΦϒδΣΫτࢦ޲͕Ͱ͖Δ! (ؔ਺ݴޠͬΆ͕͞ͳ͘ͳΔ) 15
  16. આ໌͍ͯ͠ͳ͍͜ͱ Ճච༧ఆ ͍Ζ͍ΖͳΦϒδΣΫτ - ݴޠΦϒδΣΫτ: จࣈྻ͔ΒࣜΛ࡞Δɺ͋Δ͍͸ͦͷٯ - ༧໿ΦϒδΣΫτ: lazy evaluation

    Λ࣮ݱ͢Δ - දݱࣜΦϒδΣΫτ: จͷू·Γɻจ͸γϯϘϧͷू·Γ 16
  17. RͷΦϒδΣΫτͱ͸ͳʹ͔? ·ͱΊ R͸͢΂͕ͯΦϒδΣΫτ - ΦϒδΣΫτͷܕ - σʔλܕɺmode, storage.mode - ΦϒδΣΫτͷσʔλߏ଄

    - ΦϒδΣΫτࢦ޲ϓϩάϥϛϯά 17
  18. ࢀߟࢿྉ ࿦จɺΦϯϥΠϯυΩϡϝϯτɺॻ੶ • The R Language Definition • RϓϩάϥϛϯάϚχϡΞϧ •

    Rͷجૅͱϓϩάϥϛϯάٕ๏ • RݴޠٯҾ͖ϋϯυϒοΫ 18