假设我在Rcpp中有一个List
,这里叫做x
包含矩阵。我可以使用x[0]
或其他东西提取其中一个元素。但是,如何提取该矩阵的特定元素?我的第一个想法是x[0](0,0)
,但似乎并不奏效。我尝试使用*
标志,但也不起作用。来自Rcpp中的列表的索引元素
这里是打印矩阵一些示例代码(显示矩阵可以很容易地提取):
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]));
这里打印的元素中的第一行和列?在我想要使用它的代码中,我需要提取这个元素来进行计算。