From: Christian Date: 2007-03-24T03:25:04+09:00 Subject: Re: count distinct values in csv many thanks , ruby is really great and i have to learn think "easy"! christian On 23 Mrz., 15:04, Drew Olson wrote: > Christian Schulz wrote: > > Hi, > > > i'm new to ruby. > > How could i read a tab-delimted textfile with two columns + header > > row > > and count the distinct values from the 2.column? > > Christian - > > Strangely enough, I wrote a blog post about this very topic: > > http://drewolson.wordpress.com/2007/03/13/csv-manipulation-w-ruby/ > > Here's the code linked to by the blog post: > > require 'faster_csv' > > unique_count = {} > > FCSV.foreach("myfile.csv", :headers => true) do |row| > unique_count[row[1]] ||= 0 > unique_count[row[1]] += 1 > end > > unique_count.each do |val,count| > puts "#{val} appreas #{count} time(s)" > end > > -- > Posted viahttp://www.ruby-forum.com/.