<div dir="ltr">Mario,<div><br></div><div>Your vector matched is 1-indexed, but by passing an element of this vector (match_id) to rownames[] you're treating it as if it's 0-indexed.</div><div><br></div><div>-John</div>

<div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 7, 2014 at 10:33 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello everyone,<br>
<br>
I am trying to implement a data structure using Rcpp. But I am already struggling with my first method.<br>
How things (should) work: I want to my function ("createVectorList") a data frame or matrix. Each column of the matrix gets sorted. This also holds for the rownames - storing the sorted rownames for each sort column gives me big memory footprint, but log(n) access while reading later.<br>


Basically everything is fine, but when accessing some data through a for loop I get "address 0x0, cause 'memory not mapped'".<br>
<br>
Here is my Code:<br>
<br>
#include <Rcpp.h><br>
using namespace Rcpp;<br>
<br>
// [[Rcpp::export]]<br>
List createVectorList(NumericMatrix df, CharacterVector rownames) {<br>
  List sorted_rownames(df.ncol());<br>
  for(int i = 0; i < df.ncol(); i++){<br>
    NumericVector sorted_vec = df(_,i);<br>
    std::sort(sorted_vec.begin(), sorted_vec.end());<br>
    NumericVector one_col = df(_,i);<br>
    df(_,i)=sorted_vec;<br>
    IntegerVector matched = match( sorted_vec, one_col);<br>
    CharacterVector one_sorted_row(df.nrow());<br>
    for(int j = 0; j < one_sorted_row.length(); j++){<br>
      int match_id=matched[j];<br>
      String r_name=rownames[match_id];<br>
      one_sorted_row[j]=r_name;<br>
    }<br>
    sorted_rownames[i]=one_sorted_row;<br>
  }<br>
  return Rcpp::List::create(Rcpp::Named("Matrix") = df, Rcpp::Named("rowIDX")=sorted_rownames);<br>
}<br>
<br>
There trouble is within these lines:<br>
<br>
    for(int j = 0; j < one_sorted_row.length(); j++){<br>
      int match_id=matched[j];<br>
      String r_name=rownames[match_id];<br>
      one_sorted_row[j]=r_name;<br>
    }<br>
<br>
When executing this, I get the error named above.<br>
What I thought about: rownames should be of the type "Proxy" or so, maybe thats the point?<br>
<br>
Maybe one of you has a hint.<br>
<br>
With beste regards,<br>
<br>
Mario<br>
__<br>
MD<br>
<a href="mailto:mariodeng@googlemail.com">mariodeng@googlemail.com</a><br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</blockquote></div><br></div>