<div dir="ltr"><div><div>I found the explanation alone.<br></div>The "list to data.frame" conversion was done by simply: returned_frame.<span>attr</span>(<span><span>"</span>class<span>"</span></span>) = <span><span>"</span>data.frame<span>"</span></span>;<br><br></div>This is my solution for a transposed data.frame <br><div><br></div><div>## The "R"code for the list:<br><br></div><div>mylist=list(c("1" , "", "0" , "112.6336"),c("2" , "*" , "20" , "113.0659"), c("3" , "" , "40" , "111.5833"),c("4" , "" , "60" ,"110.9704"))<br></div><div><br><br></div><div>// The Cpp code<br></div><div>#include <Rcpp.h><br><br>using namespace Rcpp;<br><br>// [[Rcpp::export]]<br>#include <Rcpp.h><br><br>using namespace Rcpp;<br><br>// [[Rcpp::export]]<br>List CheapDataFrameBuilder(List a) {<br> List returned_frame = clone(a);<br> StringVector c1(returned_frame.length());<br> StringVector c2(returned_frame.length());<br> StringVector c3(returned_frame.length());<br> StringVector c4(returned_frame.length());<br> StringVector vector(4);<br> <br> for (int j = 0; j < returned_frame.length(); ++j) { <br> vector=returned_frame(j);<br> c1(j) = vector(0);<br> c2(j) = vector(1);<br> c3(j) = vector(2);<br> c4(j) = vector(3);<br> }<br> return Rcpp::DataFrame::create(Rcpp::Named("Frame")=c1,<br> Rcpp::Named("Sync")=c2,<br> Rcpp::Named("Time")=c3,<br> Rcpp::Named("Point_1")=c4);<br>}<br><br></div><div>Everything works, however I want to convert the first, the third and the forth vector into a NumericVector. <br>I have try<code>:<br></code><code class=""><code class="">NumericVector c1=</code>as<NumericVector>(c1)</code></div><div>from Hadley website but:<br>error: redefinition of 'c1' with a different type: 'Vector<14>' vs 'Vector<16>'<br><br></div><div>Did I miss something?<br><br></div><div>Cheers<br><br></div><div>G<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-06-10 12:45 GMT+02:00 guillaume chaumet <span dir="ltr"><<a href="mailto:guillaumechaumet@gmail.com" target="_blank">guillaumechaumet@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Dear List,<br></div><div>Could I have some explanation comments on this code: <a href="https://github.com/jjallaire/rcpp-gallery/blob/gh-pages/src/2013-01-22-faster-data-frame-creation.cpp" target="_blank">https://github.com/jjallaire/rcpp-gallery/blob/gh-pages/src/2013-01-22-faster-data-frame-creation.cpp</a> ?<br></div><div>I just want to transpose the resulting data frame. However, I want to do it myself but I don't understand the code.<br><br></div><div>Thank you for your time<br><br></div><div>Cheers<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Guillaume<br></div></font></span></div>
</blockquote></div><br></div>