如何在Rcpp上使用qnorm? [英] How can I use qnorm on Rcpp?
问题描述
require(inline)
func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95,0.0,1.0) );' ,plugin="Rcpp")
错误:没有匹配的函数可以调用"qnorm5(double,int,int)"
require(inline)
func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95, 0.0, 1.0, 1, 0) );'
,plugin="Rcpp")
错误:没有匹配的函数可以调用"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()
错误:调用"qnorm5(double,double,double)"没有匹配功能
如何在Rcpp上使用qnorm?
How can I use qnorm on Rcpp?
推荐答案
通过使mean
和sd
自变量double
出现在错误消息中,因此-尝试这是一个完整的示例
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));
')
并查看示例和单元测试-我只是在单元测试文件runit.stats.R
中进行了查找,该文件具有许多用于统计"Rcpp sugar"功能的测试用例.
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.
在2012-11-14上 今天发布的Rcpp 0.10.0中,如果您想使用C样式,则可以调用执行签名R::qnorm(double, double, double, int, int)
.针对Rmath.h
编写的代码. Rcpp sugar仍然可以为您提供矢量化版本.
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.
这篇关于如何在Rcpp上使用qnorm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!