stephansun对《Exploring Everyday Things with R and Ruby》的笔记(7)

stephansun
stephansun (认真你就输了...)

读过 Exploring Everyday Things with R and Ruby

Exploring Everyday Things with R and Ruby
  • 书名: Exploring Everyday Things with R and Ruby
  • 作者: Sau Sheong Chang
  • 副标题: Learning About Everyday Things
  • 页数: 198
  • 出版社: O'Reilly Media
  • 出版年: 2012-7-19
  • 第4页
    RubyInstaller includes many native C-based extensions, so that's a bonus.
    引自第4页
    2013-03-07 20:37:15 回应
  • 第27页
    Programmers are trained in logic, and our daily work mostly involves controlling and moving bits and bytes around. So when we're faced with a chunk of data and asked to do something with it, our reactions usually involve either bolting for the nearest exit or stuffing the data into a relational database and running SQL SELECT statements on it.
    引自第27页
    2013-03-08 15:14:08 回应
  • 第73页

    勘误

    ggplot(data = df) + scale_shape_manual(name="Type", value=c(2,3,4)) +

    应该为

    ggplot(data = df) + scale_shape_manual(name="Type", values=c(2,3,4)) +
    2013-04-08 11:13:22 回应
  • 第84页

    先说一下 在 第三章目前包括Example 3-11 在内的所有R的示例代码中

    ggplot() + scale_shape_manual(name="Type", value=c(2,3,4,22)) +

    均写错了,应为

    ggplot() + scale_shape_manual(name="Type", values=c(2,3,4,22)) +

    所有的都是这个错误有点说不过去了。 另外就是本页的另一处重大错误

    DURATION.times do |t|
          data[population_size] << restrooms.inject(0) {|n,m| n + m.queue.size }
          restrooms.each {|restroom|
            queue = restroom.queue.clone
            restroom.queue.clear
            unless queue.empty?
              restroom.enter queue.shift
    end }

    运行出来的效果根本不对,去GitHub上查了代码发现是

    DURATION.times do |t|
          restroom_shortest_queue = restrooms.min {|n,m| n.queue.size <=> m.queue.size }
          data[population_size] <<  restroom_shortest_queue.queue.size # we want the queue size
          restrooms.each {|restroom|
            queue = restroom.queue.clone # clone the queue so that we don't mess up the live one
            restroom.queue.clear # clear the queue
    
            # let everyone from the queue enter the restroom first
            until queue.empty? 
              restroom.enter queue.shift # de-queue the first person in line and move him to the restroom
            end
          }

    这么严重的错误,出版前没校验的么?

    2013-08-29 00:04:55 回应
  • 第80页

    想来这页还是个疙瘩放不下 Example3-8中的代码是

    ggplot(data = df) + scale_color_discrete(name="Type") +
      geom_smooth(aes(x=population,y=mean,color="mean")) +
      geom_point(aes(x=population,y=mean,color="mean")) +
      geom_smooth(aes(x=population,y=median,color="median")) +
      geom_point(aes(x=population,y=median,color="median")) +
      geom_smooth(aes(x=population,y=max,color="max")) +
      geom_point(aes(x=population,y=max,color="max")) +
      scale_y_continuous("queue size") +
      scale_x_continuous("number of facilities in a restroom")

    用R运行得到的应该是color描绘的图形,但是书中Figure3-5显示的明显是point啊,关键是这个图的结果是正确的,还不是弄错了的图。 PS: 真怀疑我现在看的这个电子书是不是正版的

    2013-08-29 00:08:37 回应
  • 第87页
    We run the same script in Example 3-6 but change the filename from simulation1.csv to simulation4-1.csv to generate the chart in Figure 3-8.
    引自第87页

    应该为

    We run the same script in Example 3-6 but change the filename from simulation1.csv to simulation3-1.csv to generate the chart in Figure 3-8.
    引自第87页
    2013-08-29 00:11:32 回应
  • 第88页
    ggplot() + scale_shape_manual(name="Type", value=c(2,3,4,22)) + geom_smooth(data = df("simulation3"), aes(x=population,y=max)) + geom_point(data = df("simulation3"), aes(x=population,y=max,shape="max-1x12")) + geom_smooth(data = df("simulation4-4"), aes(x=population,y=max)) + geom_point(data = df("simulation4-4"), aes(x=population,y=max,shape="max-4x3")) + scale_y_continuous("queue size", breaks=0:35) + scale_x_continuous("population", breaks=seq(from=10,to=600,by=30))
    引自第88页

    怎么看怎么应该是

    ggplot() + scale_shape_manual(name="Type", value=c(2,3,4,22)) + geom_smooth(data = df("simulation4-1"), aes(x=population,y=max)) + geom_point(data = df("simulation4-1"), aes(x=population,y=max,shape="max-1x12")) + geom_smooth(data = df("simulation4-4"), aes(x=population,y=max)) + geom_point(data = df("simulation4-4"), aes(x=population,y=max,shape="max-4x3")) + scale_y_continuous("queue size", breaks=0:35) + scale_x_continuous("population", breaks=seq(from=10,to=600,by=30))
    引自第88页

    2013-08-29 01:09:58 回应