title: Manipulating NumericMatrix in Rcpp
body: <p>I'm new with Rcpp. I have read <a href="http://adv-r.had.co.nz/" rel="noreferrer">Advanced R by Hadley Wickham</a> and all Rcpp vignettes but i can't figure how to manipulate <code>NumericMatrix</code> objects.</p>
  
  <p>Is there any simple way to do things like <em>this <code>R</code> code</em></p>
  
  <pre><code>mat &lt;- matrix(1:9,3,3)
  v &lt;- matrix(2,2,2)
  mat[1,] &lt;- NA
  mat[,3] &lt;- 0.5
  mat[2:3,2:3] &lt;- v
  </code></pre>
  
  <p>other than looping on rows and columns and setting the value of each <code>mat[i,j]</code> ?</p>
  
  <hr>
  
  <p>Edit3 : Ok let's try again.</p>
  
  <p>Here's my cpp file :</p>
  
  <pre><code>#include &lt;Rcpp.h&gt;
  using namespace Rcpp;    
  
  // [[Rcpp::export]]
  NumericMatrix lissage_incapC(NumericMatrix mat) {
  // INIT
    NumericMatrix x(mat.nrow()+1,mat.ncol()+1);
    NumericMatrix out(mat.nrow(),mat.ncol());
  
    // Here i want to set x first row and first column to NA_REAL //**1
    for(int i=0; i&lt;x.nrow(); i++){
      for(int j=0; j&lt;x.ncol(); j++){
        if(i==0 || j==0)
          x(i,j) = NA_REAL; 
        x(i,j) = mat(i-1,j-1);
      }
    }
  
  
    for(int i=8; i&lt;x.nrow()-1; i++){
      for(int j=1; j&lt;x.ncol()-1; j++){
        NumericMatrix y = x(Range(i-1,i+1),Range(j-1,j+1)); 
        y(1,1) = NA_REAL; 
  
        if((i == 8) &amp; (j&gt;1))
          y.row(0) = NumericVector::get_na(); //problem here
  
        out(i,j-1) = 1/2*x(i,j) + 1/2 * mean(na_omit(y));
  
        }
      }
    out(_,out.ncol()) = 0.5; // Problem here
    out(Range(0,7),_) = out(8,_); // Problem here
    return out;
  }
  </code></pre>
  
  <p>I've pointed my problem in comments. In the first one (//**1) i have to write two loops to set first row and first column. 
  What i'm asking is : is there any simpler way to do it, like we can do in R?</p>
  
  <p>This is the same issue i have pointed out in my code's comments.</p>