title: Iterate a numeric vector in a list
body: <p>I have a list <code>NList</code> of numeric vector like</p>
  
  <pre><code>[[1]]
  [1] 1959 9 4 62
  
  [[2]]
  [1] 2280  2  13
  
  [[3]]
  [1] 15 4  13
  
  [[4]]
  [1] 2902  178   13
  </code></pre>
  
  <p>and the structure is like</p>
  
  <pre><code>list(c(1959, 13), c(2280, 178, 13), c(2612, 178, 13), c(2902, 
  178, 13), c(2389, 178, 13), c(216, 736, 13), c(2337, 178, 13), 
      c(2639, 2126, 13), c(2924, 676, 178, 13), c(2416, 674, 178, 
      13), c(2223, 13), c(842, 178, 13), c(2618, 1570, 178, 13), 
      c(854, 178, 13), c(1847, 178, 13), c(2529, 178, 13), c(511, 
      178, 13), c(2221, 736, 13), c(415, 674, 178, 13), c(2438, 
      178, 13), c(2127, 178, 13), c(1910, 2126, 13), c(1904, 674, 
      178, 13), c(2310, 674, 178, 13), c(1732, 178, 13), c(1843, 
      178, 13), c(2539, 178, 13), c(1572, 676, 178, 13), c(1616, 
      876, 13).....)
  </code></pre>
  
  <p>I want to iterate the numeric vectors in this list, I would like to do something as:</p>
  
  <pre><code>  sum&lt;- 0
    index&lt;-1
    list1 &lt;- apply(NList,1,function (i){
    #I want to get each of the numeric vector here
    row &lt;- NList[i]
  
    #then I want to iterate the numeric vector for some calculation.
    #I am expecting, for [[1]], I get f(1959,9)+f(9,4)+f(4,62), in which f is my customized function, below I use a simple multiple as example
    for (j in (1:(length(row)-1)))
    {
      origin &lt;- row[j]
      dest &lt;- row[j+1]
      #a simple calculation example...I am expecting an array of sum which is the calculation result 
      sum[index] &lt;- sum[index] + origin*dest
    }
    index &lt;- index+1  
  
    })
  </code></pre>
  
  <p>but it does not work and returns:</p>
  
  <pre><code>dim(X) must have a positive length
  </code></pre>
  
  <p>The lapply is not working for me and return sum as 0...</p>
  
  <pre><code>listR1 &lt;- lapply(NList,function (i){
    row &lt;- i
    for (j in 1:length(row))
    {origin &lt;- row[j]
    dest &lt;- row[j+1]
    sum[index] &lt;- sum[index] + origin*dest
    }
  
    })
  </code></pre>
  
  <p>Did I miss something? How can I do this?<br>
  Thanks!</p>