title: Problems creating list of lists in R
body: <p>I have been trying to create a list of lists in R. I start by creating a list of lists of prespecified length. I then iterate through a matrix using a for loop to fill the lists.  </p>
  
  <p>The problem is that I seem to be getting lists of lists of lists etc.</p>
  
  <p>My code:</p>
  
  <pre><code>potential_dups &lt;- rep(list(list()), 10)
  nearest10 &lt;- matrix(rnorm(100), nrow=10)
  
  for (i in 1:length(nearest10[ , 1])) {
    for (j in 1:10) {
      if (nearest10[i, j] &lt; 0.35 &amp;&amp; nearest10[i, j] &gt; 0) {
        potential_dups[[i]] &lt;- append(potential_dups[[i]], nearest10[i, j])
      }
    } 
  }  
  </code></pre>
  
  <p>Why is this happening? How can I create a lists of this format?</p>
  
  <pre><code>[[1]]
  [1] "Element 1A"
  [[1]]
  [2] "Element 1B"
  [[1]]
  [3] "Element 1C"
  
  [[2]]
  [1] "Element 2A"
  [[2]]
  [2] "Element 2B"
  </code></pre>
  
  <p>Additionally, I am ending up with empty list that are displayed for example as:
      [[3]]
      list()
  There first elements are NULL. I would additionally like to write script that subsets out only the non-empty lists from this data structure.</p>