草庐IT

c++ - 如何使用 R 和 Rcpp 删除 NumericVector 中的元素以进行递归

我试图了解更多关于如何使用Rcpp包的R。所以我开始使用Rcpp测试基本的排序算法。我从HadleyWickham教程开始here.我通过这种方式成功地实现了插入排序:library(Rcpp)vetor1){insertionsortRC(vetor,n-1);aux=vetor[n-1];i=n-1;while(vetor[i-1]>aux&&i>=0){vetor[i]=vetor[i-1];i--;}vetor[i]=aux;}returnvetor;}")但是这个函数需要2个参数,然后我尝试这样:cppFunction("NumericVectorinsertionsortR