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

R Object

R Object

What's R object.

Itoshi NIKAIDO

September 06, 2012
Tweet

More Decks by Itoshi NIKAIDO

Other Decks in Programming

Transcript

  1. 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
  2. ࣍ݩ਺ͱҟͳΔλΠϓΛࠞͥΒΕΔ͔Ͱ෼ྨͰ͖Δ 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
  3. 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
  4. ͍ͭͷ·ʹ͔ factor ʹͳΔɻfactor ͷͳʹ͕خ͍͔͠ GBDUPS͕ۤख > R ͸ character Λ

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

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