I am beginner in use of Rcpp and I want get faster selection of values of vectors after calculation of quantiles. In the example below, it runs well when lower and higher limits
calculated by qnorm function are manually entered (function val.sel.1). Yet, when these limits are coming from a prior calculation, no resulting vector is obtained (function val.sel.2). I am wondering what is wrong in the use I do of arguments.
Thanks in advance for any help.
Alain
R> src.1 <-'
NumericVector x = xx, p = prob;
int n = p.size() ;
int m = x.size() ;
NumericVector res(n), quant ;
for( int i=0; i<n; i++) res[i] = R::qnorm(p[i], Rcpp::mean(x), Rcpp::sd(x), 1, 0) ;
for( int i=0; i<m; i++) {
if (x[i] > 35.45295 && x[i] < 83.34705) quant.push_back(x[i]);
}
return wrap(quant) ;
'
R> val.sel.1 <- cxxfunction(signature(xx="numeric", prob="numeric"), plugin='Rcpp', body=src.1)
R> x <- c(77, 95, 16, 54, 63, 93, 44, 88, 25, 39)
R> val.sel.1(x, prob=c(0.2,0.8)) # [1] 77 54 63 44 39
R> src.2 <-'
NumericVector x = xx, p = prob;
int n = p.size() ;
int m = x.size() ;
NumericVector res(n), quant ;
for( int i=0; i<n; i++) res[i] = R::qnorm(p[i], Rcpp::mean(x), Rcpp::sd(x), 1, 0) ;
for( int i=0; i<m; i++) {
if (x[i] > res[1] && x[i] < res[2]) quant.push_back(x[i]);
}
return wrap(quant) ;
'
R> val.sel.2 <- cxxfunction(signature(xx="numeric",prob="numeric"),plugin='Rcpp', body=src.2)
R> val.sel.2(x, prob=c(0.2,0.8)) # numeric(0)