gpt4 book ai didi

r - 从 Rcpp 函数打印整数向量

转载 作者:行者123 更新时间:2023-12-03 15:07:39 24 4
gpt4 key购买 nike

如何从 Rcpp 函数打印整数向量?在我的函数中,我想打印 IntegerVector a .在 R 中,我使用例如 compnz_next(5,3,c(1,2,2)) 调用此函数

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
IntegerVector compnz_next(int n, int k, IntegerVector a) {
bool more = true;
int i;
static int h = 0;
static int t = 0;

for ( i = 0; i < k; i++ ) {
a[i] = a[i] - 1;
}
if ( 1 < t ) {
h = 0;
}

h = h + 1;
t = a[h-1];
a[h-1] = 0;
a[0] = t - 1;
a[h] = a[h] + 1;

more = ( a[k-1] != ( n - k ) );
Rcout << "a vector is:" << more << std::endl;
for ( i = 0; i < k; i++ ) {
a[i] = a[i] + 1;
}

return a;
}

最佳答案

尝试以下行:

Rf_PrintValue(a);

关于r - 从 Rcpp 函数打印整数向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28152406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com