[Rcpp-devel] Accessing list of list members to permute them
Christian Gunning
xian at unm.edu
Mon Mar 30 12:42:11 CEST 2015
On Mon, Mar 30, 2015 at 6:00 AM,
rcpp-devel-request at lists.r-forge.r-project.org <
rcpp-devel-request at lists.r-forge.r-project.org> wrote:
>
>
> // [[Rcpp::export]]
>
> List rearrangelist(List x){
> int ni=15;
> int nj=49999;
> int nk=999;
> List output;
>
> for (int i= 0 ; i<ni ; i++){
> for (int j=0 ; j<nj ; j++) {
> for (int k=0 ; j<nk ; k++){
> output[i](j,k)=x[k][0](j,i);
> }
> }
> }
> return output;
> }
First thing, you probably want to walk before you run. Get comfortable
returning a list of vectors before you start chaining a large number of
indexes together.
Second, practice getting your indexes from the objects that you're
operating on:
size_t ni = x.size();
And you probably want to fill your return list like this.
List foo;
// do stuff
foo.push_back(result);
-xian
>
--
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150330/a8ebe5ac/attachment.html>
More information about the Rcpp-devel
mailing list