I have several hashes
hash1 = { :c1234 => 0.7, :c1237 => 0.8, :c1634 => 0.6, :c1224 => 0.3, :c1291 => 0.1 }
hash2 = { :c1234 => 0.5, :c1136 => 0.2, :c1634 => 0.7, :c1524 => 0.1, :c2291 => 0.9, :c2391 => 0.7 }
hash3 = { :c1234 => 0.3, :c1136 => 0.4, :c6321 => 0.5 }
I need to create matrix from these hashes like
numhash c1234 c1237 c1634 c1224 c1291 c1136 c1524 c2291 c2391 c6321
hash1 0.7 0.8 0.6 0.3 0.1 0 0 0 0 0
hash2 0.5 0 0.7 0 0 0.2 0.1 0.9 0.7 0
hash3 0.3 0 0 0 0 0.4 0 0 0 0.5
numhash = 3 (number of hashes)
Please help me to do it in Ruby.
You should store your hashes not in many local variables, but instead in an enumerable collection, like an Array or Hash. For example, using a hash to name each hash “row”:
If you change the last map to…
then you get: