Method: Statsample::Histogram#initialize
- Defined in:
- lib/statsample/histogram.rb
#initialize(p1, min_max = false, opts = Hash.new) ⇒ Histogram
Returns a new instance of Histogram.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/statsample/histogram.rb', line 71 def initialize(p1, min_max=false, opts=Hash.new) if p1.is_a? Array range=p1 @n_bins=p1.size-1 elsif p1.is_a? Integer @n_bins=p1 end @bin=[0.0]*(@n_bins) if(min_max) min, max=min_max[0], min_max[1] range=Array.new(@n_bins+1) (@n_bins+1).times {|i| range[i]=min+(i*(max-min).quo(@n_bins)) } end range||=[0.0]*(@n_bins+1) set_ranges(range) @name="" opts.each{|k,v| self.send("#{k}=",v) if self.respond_to? k } end |