You're mixing NumericVectors, std::vectors, and XPtrs, not to mention using
plain C's memcpy to copy C++ objects. Even if it compiled, I'd be surprised if
this code worked correctly.
If you want to copy pdA into v, you should probably use std::copy with
iterators (with v as the target, not pdB
trying to feed the beast something line by line (if this works to the end it
may become an instance of quickselect() :)
int k = Rcpp::as(kr);
NumericVector pdA(pdAr);
int n = pdA.size();
//this:
//double *pdB = new double [n] ;
//becomes