[Rcpp-devel] Vectorized version of rbinom function via Rcpp

carsten Gerken gerken.carsten at gmail.com
Thu Oct 25 16:05:57 CEST 2012


Hi All,

I am trying to outsource the simulation of binomially distributed random variables to C++ via Rcpp (e.g. to replicate the R command rbinom(10,10,c(1:10)/20)). This works well as long as the third argument of the function (i.e. the probability) is a single value and not a vector. I tried to compile the following code:

rbinom_c =rcpp( signature(n = "integer",m = "integer",p="numeric") , body="int N = as<int>(n); int M = as<int>(m); NumericVector P = NumericVector(p); NumericVector res = rbinom(N,M,P); return res; ")

But the compiler expects a “double” variable in the third argument. Is there a way of fixing the code without using an explicit loop in the C++ code?


Thanks 

Carsten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121025/beedddd5/attachment.html>


More information about the Rcpp-devel mailing list