Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

r - How can I use qnorm on Rcpp?

require(inline)
func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95,0.0,1.0) );' ,plugin="Rcpp")

error: no matching function for call to ‘qnorm5(double, int, int)’

require(inline)
func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95, 0.0, 1.0, 1, 0) );' 
                   ,plugin="Rcpp")

error: no matching function for call to ‘qnorm5(double, double, double, int, int)’

require(inline)
code <-'
double a = qnorm(0.95, 0.0, 1.0);
return  Rcpp::wrap( a );
' 
func <- 
cxxfunction(, code ,plugin="Rcpp")
func()

error: no matching function for call to ‘qnorm5(double, double, double)’

How can I use qnorm on Rcpp?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

By making the mean and sd arguments double as the error message shows -- so try this is a full example

library(inline)
f <- cxxfunction(signature(xs="numeric", plugin="Rcpp", body='
     Rcpp::NumericVector x(xs);
     return Rcpp::wrap(Rcpp::qnorm(x, 1.0, 0.0));
')

and have a look at the examples and unit tests -- I just looked this up in the unit test file runit.stats.R which has a lot of test cases for these statistical 'Rcpp sugar' functions.

Edit on 2012-11-14: With Rcpp 0.10.0 released today, you can call do the signature R::qnorm(double, double, double, int, int) if you want to use C-style code written against Rmath.h. Rcpp sugar still gives you vectorised versions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...