title: Fastest way to search through a CSV and return specific array of values (Ruby)
body: <p>Basically, I would like to search through a CSV that I read in. It will be read in as an array of arrays. I want to extract only the rows where the first element of the row is equal to a certain value. If this is true, I want to then extract the row as a unit and add it to an array for further data processing.</p>
  
  <p>Right now, I am using </p>
  
  <pre><code>CSV.foreach(filepath) do |row|
    if (row[0] == experiment)
      exp1 = true &amp;&amp; (row[0] == experiment) &amp;&amp; row[7] == data)
      if exp1
        exp1_array.push(row)
      end
    end
  end
  </code></pre>
  
  <p>What is currently happening is that it is way too slow, because the CSV is a huge file. I was wondering if anyone had a really quick way to read through a CSV, check for conditions, and add to a specific array if those conditions are true.</p>
  
  <p>Also, I need to add to exp1_array if the first row says the name of experiment1, and then add to exp2_array if the first row says the name of experiment2, so that is why the first if conditional check exists.</p>
  
  <p>If anyone could help I would be immensely grateful!!</p>