From: Hans Mackowiak Date: 2013-03-05T00:12:59+09:00 Subject: Re: Efficient Ruby equivalent to Excel's "SUMIF"? i made you this: selects = ["Here", "There"] data = [ [ 'Ref', 'Count', 'Locn' ], [ 'Part1', '3', 'Here' ], [ 'Part2', '1', 'Here' ], [ 'Part1', '2', 'There' ], ] data[1..-1].group_by(&:first).map {|k,d| [k,d.inject(0){|s,v|s+v[1].to_i}] + selects.map {|s| d.select{|v|v[2]==s}.inject(0){|s,v|s+v[1].to_i} } } #=> [["Part1", 5, 3, 2], ["Part2", 1, 1, 0]] -- Posted via http://www.ruby-forum.com/.