Re: storing and manipulating columns of data



baptiste Auguié wrote:
Hi,

Being used to deal with Octave / Matlab, I'm a bit confused by Ruby structures (arrays, hashes, etc). I have this data file "data.dat" with 3 columns:

I would like to think of the columns as arrays "a", "b", "c", execute a loop along their indices, pick the values i want, and do something with them. What would be a sensible data structure for this?
I can read this datafile line by line using IO:readlines("data.dat"), but I cannot find a way to refer to one column in the array of strings generated.

You can use String#split to split each line into an array of 3 numbers. If you want to use the array values as numbers, you'll need to use String#to_f as well to convert the strings to numeric values.

ri String#split
ri String#to_f

--
RMagick OS X Installer [http://rubyforge.org/projects/rmagick/]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618]
RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]


.



Relevant Pages

  • Re: oocalc does not directly import .dat files
    ... > First row contains the first array, second row contains second array, ... gnuplot supports plotting only columns. ... > So now I have to find a software which will transpose the data file. ... > thought oocalc can do it. ...
    (Debian-User)
  • Re: Counting the Dates
    ... So you start reading the data file, adding up all the values that fall on ... you should have an array that has the total value for January ... the data has already been loaded into a DataArray() ... store the totals in a separate location so that I can reference them ...
    (microsoft.public.vb.general.discussion)
  • oocalc does not directly import .dat files
    ... First row contains the first array, second row contains second array, ... But if I want to visualize this data using gnuplot (my favorite plotting ... So now I have to find a software which will transpose the data file. ... But my data files usually have a .dat ...
    (Debian-User)
  • Re: Need Help deleting record from text file
    ... Who said you need to read an entire array into memory just to access a small portion of it? ... If you write the data in a suitable format you can later open the data file by reading just a relatively small header chunk and then read in the elements or the portion of data you require. ... How is using a database going to speed up that operation! ...
    (microsoft.public.vb.general.discussion)
  • Re: Counting the Dates
    ... calendar date, excluding weekends and holidays. ... So you start reading the data file, adding up all the values that fall on ... you should have an array that has the total value for January ... (In case I'm not making sense: I want to add up all the values found under ...
    (microsoft.public.vb.general.discussion)