title: Determining the difference between the first number of a matrix and all successive numbers
body: <p>I have a list of matrices, the first matrix of which looks as follows:</p>
  
  <pre><code>$x
  
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] 
  [1,]    1    1    1    1    1    1    1    1    1     1     1     1     1     1     1     
  [2,]    1    1    1    0    0    0    0    0    0     0     0     0     0     0     0     
  [3,]    0    0    0    0    0    0    0    1    1     1     1     0     0     0     0     
  [4,]    1    1    1    1    1    1    1    1    0     0     0     0     0     0     0
  </code></pre>
  
  <p>I am trying to create a new matrix of the same dimensions that will indicate the difference in value between the first number of each row and each successive number. Id like to use <code>abs()</code> to make this value be the absolute value of this difference. Thus, in the example above, the expected result would be:</p>
  
  <pre><code>[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] 
  [1,]    0    0    0    0    0    0    0    0    0     0     0     0     0     0     0     
  [2,]    0    0    0    1    1    1    1    1    1     1     1     1     1     1     1     
  [3,]    0    0    0    0    0    0    0    1    1     1     1     0     0     0     0     
  [4,]    0    0    0    0    0    0    0    0    1     1     1     1     1     1     1
  </code></pre>
  
  <p>I know that I can use <code>apply</code> to see the difference between the first and last columns:</p>
  
  <pre><code>abs(apply(x,1,diff, lag=15))
  [1] 0 -1 0 -1
  </code></pre>
  
  <p>However, I am not sure how to make this an iterative process in which the lag is increased from 1 to 15 to capture the information for the entire matrix. I also have some NAs in my original matrix, which id like returned as NA in the new matrix.</p>
  
  <p>Ultimately, Id like to use the solution with <code>sapply</code> to apply it across my entire list comprised of 500 matrices like the one in the example.</p>