c1 is already defined, so you simply want c1 = as<NumericVector>(c1);
That is, when you write NumericVector c1 = as<NumericVector>(c1); 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. Kevin On Wed, Jun 10, 2015 at 11:09 AM guillaume chaumet < guillaumechau...@gmail.com> wrote: > I found the explanation alone. > The "list to data.frame" conversion was done by simply: returned_frame. > attr("class") = "data.frame"; > > This is my solution for a transposed data.frame > > ## The "R"code for the list: > > mylist=list(c("1" , "", "0" , "112.6336"),c("2" , "*" , "20" , > "113.0659"), c("3" , "" , "40" , "111.5833"),c("4" , "" , "60" ,"110.9704")) > > > // The Cpp code > #include <Rcpp.h> > > using namespace Rcpp; > > // [[Rcpp::export]] > #include <Rcpp.h> > > using namespace Rcpp; > > // [[Rcpp::export]] > List CheapDataFrameBuilder(List a) { > List returned_frame = clone(a); > StringVector c1(returned_frame.length()); > StringVector c2(returned_frame.length()); > StringVector c3(returned_frame.length()); > StringVector c4(returned_frame.length()); > StringVector vector(4); > > for (int j = 0; j < returned_frame.length(); ++j) { > vector=returned_frame(j); > c1(j) = vector(0); > c2(j) = vector(1); > c3(j) = vector(2); > c4(j) = vector(3); > } > return Rcpp::DataFrame::create(Rcpp::Named("Frame")=c1, > Rcpp::Named("Sync")=c2, > Rcpp::Named("Time")=c3, > Rcpp::Named("Point_1")=c4); > } > > Everything works, however I want to convert the first, the third and the > forth vector into a NumericVector. > I have try: > NumericVector c1=as<NumericVector>(c1) > from Hadley website but: > error: redefinition of 'c1' with a different type: 'Vector<14>' vs > 'Vector<16>' > > Did I miss something? > > Cheers > > G > > > 2015-06-10 12:45 GMT+02:00 guillaume chaumet <guillaumechau...@gmail.com>: > >> Dear List, >> Could I have some explanation comments on this code: >> https://github.com/jjallaire/rcpp-gallery/blob/gh-pages/src/2013-01-22-faster-data-frame-creation.cpp >> ? >> I just want to transpose the resulting data frame. However, I want to do >> it myself but I don't understand the code. >> >> Thank you for your time >> >> Cheers >> >> Guillaume >> > > _______________________________________________ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel