title: In R, how do you loop over the rows of a data frame really fast?
body: <p>Suppose that you have a data frame with many rows and many columns.</p>
  
  <p>The columns have names. You want to access rows by number, and columns by name.</p>
  
  <p>For example, one (possibly slow) way to loop over the rows is</p>
  
  <pre><code>for (i in 1:nrow(df)) {
    print(df[i, "column1"])
    # do more things with the data frame...
  }
  </code></pre>
  
  <p>Another way is to create "lists" for separate columns (like <code>column1_list = df[["column1"]</code>), and access the lists in one loop. This approach might be fast, but also  inconvenient if you want to access many columns.</p>
  
  <p>Is there a fast way of looping over the rows of a data frame? Is some other data structure better for looping fast?</p>