Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/arraymethods.rb

Instance Method Summary collapse

Instance Method Details

#cc(other) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/arraymethods.rb', line 78

def cc(other)
  x, y = to_xy(other)
  #puts "CC : N = #{x.size}"
  if x.size > 0 
    correlation(x,y)
  else
    nil
  end
end

#to_xy(other) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/arraymethods.rb', line 65

def to_xy(other)
  raise "Please give Hash as argument" if !other.is_a? Hash
  arr = self.keys.inject([]) do |a,k|
    if other[k] and self[k]
      a << [self[k].to_f, other[k].to_f]
    end
    a
  end
  x = arr.map{|i| i[0]}
  y = arr.map{|i| i[1]}
  [ x, y ]
end