<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi KK,<div class=""><br class=""></div><div class="">thank you. This helped a lot. Also the stream operators is something I was also looking for :)</div><div class="">bye</div><div class="">Wasili</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 29.05.2017 um 20:21 schrieb Qiang Kou <<a href="mailto:qkou@umail.iu.edu" class="">qkou@umail.iu.edu</a>>:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi, Wasilios,<div class=""><br class=""></div><div class="">I modified your code a little and paste below. I hope this helps. </div><div class=""><br class=""></div><div class="">Best,</div><div class=""><br class=""></div><div class="">KK</div><div class=""><br class=""></div><div class=""><div class=""><br class=""></div><div class="">df <- data.frame(first=c("a","A", "aA"), second=c("b","B","bB"), third=rep(c("c","C","cC"),4))</div><div class="">PLAYGROUND = new.env()</div><div class="">PLAYGROUND$testData <- split(df, df$first)</div><div class=""><br class=""></div><div class="">src_4='</div><div class="">Rcpp::Environment e(env);</div><div class="">Rcpp::List splitted ( e["testData"] );</div><div class="">Rprintf("splitted contains %d entries \\n", splitted.size());</div><div class="">for(int i = 0; i< splitted.size(); i++){</div><div class="">  Rcpp::DataFrame df(splitted[i]);</div><div class="">  Rcpp::Rcout << "element " << i << " has " << df.nrow() << " rows " << df.ncol() << " cols" << std::endl;</div><div class="">  Rcpp::CharacterVector df_names = df.names();</div><div class="">  Rcpp::Rcout << "col names: " << df_names << std::endl;</div><div class="">  Rcpp::CharacterVector v = df[0];</div><div class="">  Rcpp::Rcout << v << std::endl;</div><div class="">}</div><div class="">return splitted;</div><div class="">'</div><div class=""><br class=""></div><div class="">library(inline)</div><div class=""><br class=""></div><div class="">fun_4 <- cxxfunction(sig=signature(env="environment"), body = src_4, plugin = "Rcpp")</div><div class="">ret_4 <- fun_4(PLAYGROUND)</div><div class=""><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, May 28, 2017 at 2:02 PM, Wasilios Goutas <span dir="ltr" class=""><<a href="mailto:wasili@goutas.de" target="_blank" class="">wasili@goutas.de</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br class="">
<br class="">
I’m pretty new to Rcpp and tried some examples and was surprised how nice C++ can be included in R code :)<br class="">
<br class="">
Currently I’m struggling with accessing the Elements of data.frames in C++ and hope you will give me a hint on how to get the values expected out of it.<br class="">
<br class="">
Below is an example I created to learn how to access the values out of a splitter data.frame.<br class="">
As you can see I use an environment object as parameter containing a splitted data.frame with the name ‚testData‘ in it.<br class="">
What I try to do is accessing the elements of the splitter data.frame one by one, but I’m not sure what kind of object type they are. It should be a kind of List (which seems to be a Vector in Rcpp) but I’m not sure.<br class="">
I read that a DataFrame is a list of vectors which all have the same length. but I was not able to find any information on how to get the column names and how to access the elements of the DataFrame object.<br class="">
<br class="">
It would be very nice if you could show me based on this code how to access the elements of the splitter data.frame in C++ and maybe also the column names :)<br class="">
Thanks in advance<br class="">
Wasili<br class="">
<br class="">
<br class="">
(the commented lines crashes R ones uncommented)<br class="">
<br class="">
df <- data.frame(first=c("a","A", "aA"), second=c("b","B","bB"), third=rep(c("c","C","cC"),4))<br class="">
PLAYGROUND = new.env()<br class="">
PLAYGROUND$testData <- split(df, df$first)<br class="">
<br class="">
src_4='<br class="">
  Rcpp::Environment e(env);<br class="">
  Rcpp::List splitted ( e["testData"] );<br class="">
  Rprintf("splitted contains %d entries \\n", splitted.size());<br class="">
  for(int i = 0; i< splitted.size(); i++){<br class="">
    Rprintf("typeof splitted[%d] = %s \\n", i, typeid(splitted[i]).name());<br class="">
    Rcpp::DataFrame df = Rcpp::as<Rcpp::DataFrame>(<wbr class="">splitted[i]);<br class="">
//    Rprintf("typeof df = %s \\n", i, typeid(df).name());<br class="">
    Rprintf(" element %d has %d rows \\n", i, df.nrow());<br class="">
    for(int k=0; k < df.nrow(); k++){<br class="">
//      Rcpp::GenericVector v = df[k];<br class="">
//      Rprintf("typeof v = %s \\n", typeid(v).name());<br class="">
//      Rprintf(" row [%d] = %s \\n", k, df[k]);<br class="">
    }<br class="">
  }<br class="">
  return splitted;<br class="">
'<br class="">
rm(fun_4)<br class="">
fun_4 <- cxxfunction(sig=signature(env=<wbr class="">"environment"), body = src_4, plugin = "Rcpp")<br class="">
ret_4 <- fun_4(PLAYGROUND)<br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
Rcpp-devel mailing list<br class="">
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" class="">Rcpp-devel@lists.r-forge.r-<wbr class="">project.org</a><br class="">
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank" class="">https://lists.r-forge.r-<wbr class="">project.org/cgi-bin/mailman/<wbr class="">listinfo/rcpp-devel</a></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature"><div dir="ltr" class="">Qiang Kou<div class=""><a href="mailto:qkou@umail.iu.edu" target="_blank" class="">qkou@umail.iu.edu</a><br class=""><div class="">School of Informatics and Computing, Indiana University</div><div class=""><br class=""></div></div></div></div>
</div></div></div>
</div></blockquote></div><br class=""></div></body></html>