<div dir="ltr"><div><div><div><div><div>c1 is already defined, so you simply want<br><br></div>    c1 = as<NumericVector>(c1);<br><br></div>That is, when you write<br><br></div>    NumericVector c1 = as<NumericVector>(c1);<br><br></div>you are effectively trying to create a new NumericVector called `c1` -- but since an object with the name `c1` already exists in scope, that fails.<br><br></div>Kevin<br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 10, 2015 at 11:09 AM guillaume chaumet <<a href="mailto:guillaumechaumet@gmail.com">guillaumechaumet@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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><code>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><div dir="ltr"><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><font color="#888888"><br></font></span></div><span><font color="#888888"><div><br></div><div>Guillaume<br></div></font></span></div>
</blockquote></div><br></div>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">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" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></blockquote></div>