在 Rcpp 中访问命名列表元素 [英] Accessing Named List Elements in Rcpp
本文介绍了在 Rcpp 中访问命名列表元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过 Rcpp 中的名称访问命名列表元素
I would like to access a named list element by name in Rcpp
在 R
> b = list(bgroups=c(1,1,1,1,1,0,0,0,0,0))
> b$bgroups
[1] 1 1 1 1 1 0 0 0 0 0
然后当试图在 Rcpp 中访问它时我试过了:
Then when trying to access this in Rcpp I have tried:
cppFunction(
"
void f(List & b){
std::vector<int> c(10) = as<std::vector<int>> b['bgroups'];
}
"
)
...
NumericVector groupings = b['bgroups'];
...
NumericVector groupings(10) = b(4);
但无济于事.
我已经查看了 Dirk 的许多有用答案,但一直无法建立联系https://github.com/eddelbuettel/rcppexamples/blob/master/src/ListExample.cpp
I've reviewed Dirk's many helpful answers, but have not been able to make the connection https://github.com/eddelbuettel/rcppexamples/blob/master/src/ListExample.cpp
推荐答案
不确定我是否完全理解您的问题,但您是否在 CppFunction 下面感到疲倦.
Not sure if I understand your question completely but have you tired below in your CppFunction.
NumericVector Bgroups = as<NumericVector>(b["bgroups"]);
这篇关于在 Rcpp 中访问命名列表元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文