<div>
<p class="western" style="margin-bottom:0cm">
</p><p class="western" style="margin-bottom:0cm">Hello all,</p>
<p class="western" style="margin-bottom:0cm">first of all, I would
like to apologize to ask questions without exhaustively searching for
the answer by myself. Dirk and Garrett were very nice to run my code,
even when haven't did my homework. I promise I got the
lesson and I will work harder before posting another question... </p>
<p class="western" style="margin-bottom:0cm">I would like to report
the mistake, maybe some beginner could benefit of this.</p>
<p class="western" style="margin-bottom:0cm">Following Dirk's idea
I've isolated the problem, running small chunks of code, I was doing</p>
<p class="western" style="margin-bottom:0cm"><br></p><p class="western" style="margin-bottom:0cm">call.gibbs <- cxxfunction(</p>
<p class="western" style="margin-bottom:0cm"> signature(x="numeric",
y="numeric",N="interger", w="numeric",
p="numeric", <b>fun= "function" </b>)
,... </p>
<p class="western" style="margin-bottom:0cm"><br>
</p>
<p class="western" style="margin-bottom:0cm">where <b>fun</b> was
the R's sample function</p>
<p class="western" style="margin-bottom:0cm">
pos =
as<int>(f(ya.size(), 1, "FALSE", betaP)) - 1; </p>
<p class="western" style="margin-bottom:0cm">as R was reporting a
vector position I've subtracted 1 to match vector positions on the
rest of the code. Worked well, I even created a package with the
prototype. importing R's sample function as an example
in <b>Rcpp-introduction</b>.</p>
<p class="western" style="margin-bottom:0cm">I don't know
what happened later...</p>
<p class="western" style="margin-bottom:0cm">I found a similar way
to find the same answer I was searching with sample function, one I
could easily code in c++ </p>
<p class="western" style="margin-bottom:0cm"><br>
</p>
<p class="western" style="margin-bottom:0cm">prob <- c(0.03,
0.001, 0.15, 0.0001, 0.30, 0.27, 0.2489) </p>
<p class="western" style="margin-bottom:0cm"># the way I was used to
do</p>
<p class="western" style="margin-bottom:0cm">table(sample(1:7, 100,
replace=TRUE, prob=prob)) </p>
<p class="western" style="margin-bottom:0cm"># the new way</p>
<p class="western" style="margin-bottom:0cm">table(sapply(1:100,
function(x) which(cumsum(prob)>runif(1))[1])) </p>
<p class="western" style="margin-bottom:0cm"><br></p><p class="western" style="margin-bottom:0cm">hope it could
be useful to some one, I spent two days to figure it out.</p>
<p class="western" style="margin-bottom:0cm">Ricardo</p><p></p></div>