Dear Listers,
I am trying to use "rbinom" in my C code, but i always get zeros as output no matter the probability. Am not sure what I am doing wrong because the function has worked before. Attached in an example. Noticed that "rbinom" expects 'n' to be REAL.
Regards, Vumani
 
R  2.3.1 (2006-06-01)
Windows XP
Gcc
/* Called this file binom.c and then ran rcmd shlib on it */#include <R.h>#include <Rmath.h>#include <math.h>#include <Rdefines.h>SEXP binomial(SEXP r, SEXP n, SEXP p){ int i; SEXP out; PROTECT(out = allocVector(REALSXP,INTEGER(r)[0]));  for(i = 0; i < INTEGER(r)[0]; ++i){  REAL(out)[i] = rbinom(REAL(n)[0],REAL(p)[0]); } Rprintf("%d   %f   %f\n",INTEGER(r)[0],REAL(n)[0],REAL(p)[0]); UNPROTECT(1); return(out);}
 
### used theses line in R
dyn.load("binom.dll").Call("binomial",as.integer(10),as.double(1),as.double(0.4))dyn.unload("binom.dll")
_________________________________________________________________
Try Live.com - your fast, personalized homepage with all the things you care about in one place.
http://www.live.com/getstarted
	[[alternative HTML version deleted]]

