Beispiel #1
0
// [[Rcpp::export]]
NumericVector freqsempiricalC(NumericVector x_) {
  Rcpp::NumericVector x = Rcpp::clone(x_);
  int n=x.length();
  double sum=0;
  for (int i=0;i<n;i++) {
    sum+=x[i];
  }
  x=x/sum;
  return x;
}
// [[Rcpp::export]]
double parallelVectorSum(Rcpp::NumericVector x) {
  
  // declare the SumBody instance 
  Sum sum(x);
  
  // call parallel_reduce to start the work
  parallelReduce(0, x.length(), sum);
  
  // return the computed sum
  return sum.value;
}
Beispiel #3
0
// [[Rcpp::export]]
NumericVector freqsshrinkC(NumericVector y_,double lambda) {
  Rcpp::NumericVector y = Rcpp::clone(y_);
  int m=y.length();
  double n=0;
  for (int i=0;i<m;i++) {
    n+=y(i);
  }
  y=y/n;

NumericVector add(m,lambda/m);
   y=y*(1-lambda);

  y+=add;
  return y;
}
Beispiel #4
0
//[[Rcpp::export]]
Rcpp::NumericVector getRange(Rcpp::NumericVector x, const bool na_rm) {
    Rcpp::NumericVector out(2);
    out[0] = R_PosInf;
    out[1] = R_NegInf;

    int n = x.length();
    for(int i = 0; i < n; ++i) {
	if (!na_rm && R_IsNA(x[i])) {
	    out[0] = NA_REAL;
	    out[1] = NA_REAL;
	    return(out);
	}
	
	if (x[i] < out[0]) out[0] = x[i];
	if (x[i] > out[1]) out[1] = x[i];
    }
    
    return(out);
}