title: trying to append a list, but something breaks
body: <p>I'm trying to create an empty list which will have as many elements as there are <code>num.of.walkers</code>. I then try to append, to each created element, a new sub-list (length of new sub-list corresponds to a value in <code>a</code>.</p>
  
  <p>When I fiddle around in R everything goes smooth:</p>
  
  <pre><code>list.of.dist[[1]] &lt;- vector("list", a[1])
  list.of.dist[[2]] &lt;- vector("list", a[2])
  list.of.dist[[3]] &lt;- vector("list", a[3])
  list.of.dist[[4]] &lt;- vector("list", a[4])
  </code></pre>
  
  <p>I then try to write a function. Here is my feeble attempt that results in an error. Can someone chip in what am I doing wrong?</p>
  
  <pre><code>countNumberOfWalks &lt;- function(walk.df) {
      list.of.walkers &lt;- sort(unique(walk.df$label))
      num.of.walkers &lt;- length(unique(walk.df$label))
  
      #Pre-allocate objects for further manipulation
      list.of.dist &lt;- vector("list", num.of.walkers)
      a &lt;- c()
  
      # Count the number of walks per walker.
      for (i in list.of.walkers) {
          a[i] &lt;- nrow(walk.df[walk.df$label == i,])
      }
      a &lt;- as.vector(a)
  
      # Add a sublist (length = number of walks) for each walker.
      for (i in i:num.of.walkers) {
          list.of.dist[[i]] &lt;- vector("list", a[i])
      }
      return(list.of.dist)
  }
  
  &gt; num.of.walks.per.walker &lt;- countNumberOfWalks(walk.df)
  Error in vector("list", a[i]) : vector size cannot be NA
  </code></pre>