相关疑难解决方法(0)

使用dnorm与RcppArmadillo

R,我正在尝试运行sourceCpp此文件:

#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]

using namespace arma; 
using namespace Rcpp;

// [[Rcpp::export]]
vec dnormLog(vec x, vec means, vec sds) {
    int n = x.size();
    vec res(n);
    for(int i = 0; i < n; i++) {
        res[i] = log(dnorm(x[i], means[i], sds[i]));
    }
return res;
}
Run Code Online (Sandbox Code Playgroud)

看到这个答案,看看我从哪里获得了这个功能.这会引发错误:

no matching function for call to 'dnorm4'

这是我希望通过使用循环来防止的确切错误,因为引用的答案提到dnorm仅针对其第一个参数进行向量化.我担心答案是显而易见的,但我尝试R::在之前添加dnorm,尝试使用NumericVector而不是在前面vec使用log().没运气.但是,R::之前添加dnorm会产生单独的错误:

too few arguments to …
Run Code Online (Sandbox Code Playgroud)

c++ r rcpp

3
推荐指数
1
解决办法
488
查看次数

标签 统计

c++ ×1

r ×1

rcpp ×1