Class: BioTable::Statistics::Accumulate
- Inherits:
-
Object
- Object
- BioTable::Statistics::Accumulate
- Defined in:
- lib/bio-table/statistics.rb
Instance Method Summary collapse
- #add(row, type) ⇒ Object
-
#initialize ⇒ Accumulate
constructor
A new instance of Accumulate.
- #write(writer) ⇒ Object
Constructor Details
#initialize ⇒ Accumulate
Returns a new instance of Accumulate.
17 18 19 |
# File 'lib/bio-table/statistics.rb', line 17 def initialize @columns = [] end |
Instance Method Details
#add(row, type) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bio-table/statistics.rb', line 21 def add row, type if type == :header @header = row else row.each_with_index do | e,i | @columns[i] = [] if not @columns[i] @columns[i] << e.to_f end end end |
#write(writer) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bio-table/statistics.rb', line 32 def write writer vectors = @columns.map { |c| c.to_scale } writer.write(TableRow.new("stat",@header),:header) sizes = @columns.map { |c| c.size } writer.write(TableRow.new("size",sizes),:row) writer.write(TableRow.new("min",vectors.map { |v| v.min }),:row) writer.write(TableRow.new("max",vectors.map { |v| v.max }),:row) writer.write(TableRow.new("median",vectors.map { |v| v.median }),:row) writer.write(TableRow.new("mean",vectors.map { |v| v.mean }),:row) writer.write(TableRow.new("sd",vectors.map { |v| v.sd }),:row) writer.write(TableRow.new("cv",vectors.map { |v| v.coefficient_of_variation }),:row) end |