From: timr Date: 2009-09-28T00:15:04+09:00 Subject: Re: 2D array to array of hashes with repeating header data = [[:time, :pressure],[0,2.3],[1,4.1],[2,7.56],...] axes = data.shift #shift the axes labels out from the data set new_data = data.collect{|point| {axes[0] => point[0], axes[1] => point [1]}} #pair the axes with the data by iterating and collecting the results Tim On Sep 26, 11:10 pm, Jason Lillywhite wrote: > I have this array: > data = [[:time, :pressure],[0,2.3],[1,4.1],[2,7.56],...] > > All the arrays in data could have an arbitrary number of items in it and > the total number of arrays in data is arbitrary but all arrays will be > the same size and the first array will always be the "header" array. > > I need to convert data to an array that looks like this: > > new_data = > [{:time=>0,:pressure=>2.3},{:time=>1,:pressure=>4.1},{:time=>2,:pressure=>7 .56}] > > Is there a straight forward way to set this up? I'm happy with hints. > Thank you! > -- > Posted viahttp://www.ruby-forum.com/.