<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jul 11, 2014 at 3:19 AM, Mario Deng <span dir="ltr"><<a href="mailto:mariodeng@googlemail.com" target="_blank">mariodeng@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
But when I do "matched[j+1] = matched[j]+1;" everything crashes, I don't get any error informations etc. Also, is there a way to avoid that the R instance/RStudio crashes?<br></blockquote><div><br></div><div>
I was able to compile and run part of your code on linux outside R Studio. I did not get any problems with the indexing into the matched variable even when I changed "matched[j+1] = matched[j] + 1".</div><div><br>
</div><div>I did however get an index error on the line right after. It is where you set the names variable. After I commented out that line the error goes away. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
// [[Rcpp::export]]<br>
List createVectorList_Numeric_cpp(NumericMatrix df) {<br>
CharacterVector rownames = VECTOR_ELT(df.attr("dimnames"), 0);<br>
CharacterVector colnames = VECTOR_ELT(df.attr("dimnames"), 1);<br>
// Check Dimnames<br>
if (df.nrow() != rownames.size() ) {<br>
throw Rcpp::exception("Dimensions and corrosponding names differ in length");<br>
}<br>
List vectorList(df.ncol());<br>
for(int i = 0; i < df.ncol(); i++){<br>
NumericVector sorted_vec = df(_,i);<br>
sorted_vec=sorted_vec.sort();<br>
NumericVector one_col = df(_,i); </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
IntegerVector matched = match(sorted_vec, one_col);<br>
for(int j = 0; j < (matched.size() - 1); j++){<br>
if( matched[j] >= matched[j+1] ){<br>
const int tmp = matched[j]+1;<br>
matched[j+1] = tmp;<br>
}<br>
}<br></blockquote><div><br></div><div>I had to comment out the line below to avoid an index error. I'm using Rcpp 0.11.2 <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
sorted_vec.attr("names")=rownames[matched-1];</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
vectorList[i]=sorted_vec;<br>
}<br>
vectorList.attr("names") = colnames;<br>
CharacterVector classIDs = CharacterVector::create("VectorList", "list");<br>
vectorList.attr("class") = classIDs;<br>
return vectorList;<br>
}<br><br></blockquote><div><br></div><div>Cheers,</div><div>Sameer </div></div></div></div>