title: Get positions for NAs only in the "middle" of a matrix column
body: <p>I want to obtain an index that refers to the positions of NA values in a matrix where the index is true if a given cell is NA and there is at least one non-NA value before and after it in the column. For example, given the following matrix</p>
  
  <pre><code>     [,1] [,2] [,3] [,4]
  [1,]   NA    1   NA    1
  [2,]    1   NA   NA    2
  [3,]   NA    2   NA    3
  </code></pre>
  
  <p>the only value of the index that comes back TRUE should be [2,2].</p>
  
  <p>Is there a compact expression for what I want to do? If I had to I could loop through columns and use something like <code>min(which(!is.na(x[,i])))</code> to find the first non-NA value in each column, and then set all values before that to FALSE (and the same for all values after the max). This way I would not select leading and trailing NA values. But this seems a bit messy, so I'm wondering if there is a cleaner expression that does this without loops.</p>
  
  <p><strong>EDIT</strong> To be valid an NA value only needs to have a non-NA value before and after it somewhere within the column, but not necessarily adjacent to it. For instance, if a column was defined by c(NA, 3, NA, NA, NA, 4, NA), the NA's I want to find would be the ones at positions 3, 4, and 5, as these are enclosed by non-NA values.</p>