title: Iterating over lists stored in data.frame in R
body: <p>I think this is a beginner question, but I don't appear to have the right vocabulary for an effective Google search.</p>
  
  <p>I have a data.frame, <code>final</code>, which contains a list of <code>clusters</code>, each of which is a list of strings.</p>
  
  <p>I would like to iterate over the list of strings in each cluster: a for loop within a for loop.</p>
  
  <pre><code>for (j in final$clusters){
      for (i in final$clusters$`j`){
          print final$clusters$`j`[i]
      }
  }
  </code></pre>
  
  <p><code>j</code> corresponds to the lists in <code>clusters</code>, and <code>i</code> corresponds to the items in <code>clusters[j]</code></p>
  
  <p>I was trying to do this by using the length of each cluster, which I thought would be something like <code>length(final$clusters[1])</code>, but that gives 1, not the length of list.</p>
  
  <p>Also, <code>final$clusters[1]</code> gives $'1', and on the next line, all the strings in cluster 1.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: output of <code>dput(str(final))</code>, as requested:</p>
  
  <pre><code>List of 2
   $ clusters     :List of 1629
    ..$ 1   :
    ..$ 2   : 
    ..$ 3   : 
    ..$ 4   : 
    ..$ 5   : 
    ..$ 6   : 
    ..$ 7   : 
    ..$ 8   : 
    ..$ 9   : 
    ..$ 10  : 
    .. [list output truncated]
   $ cluster_stats: num [1:1629, 1:6] 0.7 0.7 0.7 0.7 0.7 0.7 ...
    ..- attr(*, "dimnames")=List of 2
    .. ..$ : chr [1:1629] "1" "2" "3" "4" ...
    .. ..$ : chr [1:6] "min" "qu1" "median" "mean" ...
  NULL
  </code></pre>