lib/locat/counter.rb
# Compute the ratios between each group,
# returning a two-dimensional array.
Compute the ratios between each group,
returning a two-dimensional array.
Compute the ratios between each group returning a two - dimensional array .
def ratio
      @ratio ||= (
        rcounts = counts.dup
        rcounts['Total'] = total
        r = Array.new(rcounts.size+1){ [] }
        x = 1
        rcounts.each do |type1, count1|
          r[x][0] = type1
          y = 1
          rcounts.each do |type2, count2|
            r[0][y] = type2
            if count2 == 0 or count2 == 0
              r[x][y] = 0
            else
              r[x][y] = (1000 * (count2.to_f / count1.to_f)).round.to_f / 1000.0
            end
            y += 1
          end
          x += 1
        end
        r
      )
    end
def ratio @ratio ||= ( rcounts = counts . dup rcounts [ 'Total' ] = total r = Array . new ( rcounts . size + 1 ) { [ ] } x = 1 rcounts . each do | type1 , count1 | r [ x ] [ 0 ] = type1 y = 1 rcounts . each do | type2 , count2 | r [ 0 ] [ y ] = type2 if count2 == 0 or count2 == 0 r [ x ] [ y ] = 0 else r [ x ] [ y ] = ( 1000 * ( count2 . to_f / count1 . to_f ) ) . round . to_f / 1000.0 end y += 1 end x += 1 end r ) end
Compute the ratios between each group,
returning a two-dimensional array.
Compute the ratios between each group returning a two - dimensional array .