R言語で『集合知プログラミング』
やっと本が届いたのでちょこちょことR言語に翻訳してみる。
逐語訳じゃなくて、意訳(超訳?)になりますけど。
2.2 嗜好の収集(p10)
Lisa.Rose <- c(2.5, 3.5, 3.0, 3.5, 2.5, 3.0) Gene.Seymour <- c(3.0, 3.5, 1.5, 5.0, 3.5, 3.0) Michael.Phillips <- c(2.5, 3.0, NA, 3.5, NA, 4.0) Claudia.Puig <- c(NA, 3.5, 3.0, 4.0, 2.5, 4.5) Mick.LaSalle <- c(3.0, 4.0, 2.0, 3.0, 2.0, 3.0) Jack.Matthews <- c(3.0, 4.0, NA, 5.0, 3.5, 3.0) Toby <- c(NA, 4.5, NA, 4.0, 1.0, NA) critics <- cbind(Lisa.Rose, Gene.Seymour, Michael.Phillips, Claudia.Puig, Mick.LaSalle, Jack.Matthews, Toby) rownames(critics)<- c("Lady.in.the.Water", "Snakes.on.a.Plane", "Just.My.Luck", "Superman.Returns", "You.Me.and.Dupree", "The.Night.Listener") critics # Lisa.Rose Gene.Seymour Michael.Phillips Claudia.Puig Mick.LaSalle Jack.Matthews Toby # Lady.in.the.Water 2.5 3.0 2.5 NA 3 3.0 NA # Snakes.on.a.Plane 3.5 3.5 3.0 3.5 4 4.0 4.5 # Just.My.Luck 3.0 1.5 NA 3.0 2 NA NA # Superman.Returns 3.5 5.0 3.5 4.0 3 5.0 4.0 # You.Me.and.Dupree 2.5 3.5 NA 2.5 2 3.5 1.0 # The.Night.Listener 3.0 3.0 4.0 4.5 3 3.0 NA critics[,"Toby"] # Lady.in.the.Water Snakes.on.a.Plane Just.My.Luck Superman.Returns You.Me.and.Dupree The.Night.Listener # NA 4.5 NA 4.0 1.0 NA # NAが混ざるのがいやなら temp <- na.omit(critics[,"Toby"]) temp[1:length(temp)] # Snakes.on.a.Plane Superman.Returns You.Me.and.Dupree # 4.5 4.0 1.0