Skip to content
Prev 2288 / 10988 Next

[Rcpp-devel] Rcpp equivalent of sample()?

Thanks Dirk.  Passing the addition function in the includes argument worked
great.

Also, one of the links from your suggested Google search led me to this
(working) example for std::accumulate:

src <- 'NumericVector xx(x);
return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));'
fx <- cxxfunction(signature( x = "numeric" ),body=src,plugin = "Rcpp")
fx(1:10)  # 55

I had been copying the quickref and using:  std::accumulate( xx.begin(),
xx.end(),std::plus<double>(),0.0)

I think this might be a typo where the last two arguments are transposed
(which I shouldn't have noticed after browsing the function's c++
reference<http://www.cppreference.com/wiki/algorithm/accumulate>),
as the following works just fine:  std::accumulate( xx.begin(),
xx.end(),0.0,std::plus<double>())

Chris
On Sat, May 14, 2011 at 5:29 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110514/ed55ffb0/attachment.htm>