title: implementing apply function in Rcpp
body: <p>I have been trying to implement apply function in Rcpp so far the code looks like this</p>
  
  <pre><code>//[[Rcpp::export]]
  NumericVector apply(NumericMatrix x,int dim,Function f){
    NumericVector output;
    if(dim==1){
     for(int i=0;i&lt;x.nrow();i++){
       output[i]=f(x(i,_));
     }    
    }
    else if(dim==2){
     for(int i=0;i&lt;x.ncol();i++){
       output[i]=f(x(_,i));
     }
    }
    return(output);
  } 
  </code></pre>
  
  <p>but i'm getting an error "cannot convert SEXP to double in assignment" in line 6 and 11. Is there any way to convert the value returned by an arbitrary function to double? also is there a sugar function for the apply function.   </p>