Hello

I'm a Rcpp newbie, so sorry if the question is trivial.

I have an R object which is a list of 1000 elements. Each elements is a result from a discrete wavelet transform (from package wmtsa) with 5 elements. One of them have a 50000 rows and 16 colums.

The first level (1000) are in fact random signals of 50 000 days. On each of them i ran a DWT that separated each signal into 16 components (of decreasing frequency) for each day thus resulting in a 50000 days * 16 components matrix for each of the 1000 signals.

I would like to sort it like that: for each component (a list of 16 elements) having for each day (50000 rows) the 1000 signals (1000 columns)


here are the objects in R:

dwtlist: 1000 elements * 5 elements* (50000*16) matrix
sortdwtlist:16 elements*(50000*1000) matrix

the code in R:

for(i in 1:16){

    for(j in 1:50000){

        for (k in 1:1000){

            sortdwtlist[[i]][j,k]<-dwtlist[[k]][[1]][j,i]
}
}
}


This takes about 27 minutes to complete.

I thus tried to put in C++ using Rcpp (i'm using sourceCpp):

#include <Rcpp.h>
using namespace Rcpp;

// [[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;
}


But it doesn't work. error stops at the line of permutation, so i'm sure there's something with the types inside the list.
Can someone help me?

Thank you!



_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to