假设我List
在 Rcpp 中有一个,这里称为x
包含矩阵。x[0]
我可以使用或其他东西提取其中一个元素。但是,如何提取该矩阵的特定元素?我的第一个想法是,x[0](0,0)
但这似乎不起作用。我尝试使用*
标志,但也不起作用。
这是一些打印矩阵的示例代码(显示矩阵可以很容易地提取):
library("Rcpp")
cppFunction(
includes = '
NumericMatrix RandMat(int nrow, int ncol)
{
int N = nrow * ncol;
NumericMatrix Res(nrow,ncol);
NumericVector Rands = runif(N);
for (int i = 0; i < N; i++)
{
Res[i] = Rands[i];
}
return(Res);
}',
code = '
void foo()
{
List x;
x[0] = RandMat(3,3);
Rf_PrintValue(wrap( x[0] )); // Prints first matrix in list.
}
')
foo()
如何更改Rf_PrintValue(wrap( x[0] ));
此处的行以打印第一行和第一列中的元素?在我想使用它的代码中,我需要提取这个元素来进行计算。