[Rcpp-devel] data.frame from R to C++?
deqiangs at bcm.edu
Tue Apr 12 10:57:45 CEST 2011
Thanks very much for your example. From this example I learned how to passing data back and forth between R and C++.
The example is R code and uses piece of C++ code in side R program.
Well, it's better if you put this example(by only making slight changes to make R embeded in C++) inside package RInside.
Accessing data by column name is the feature I ( and other people) usually want.
However, is there a way to access the data Frame by row number?
On Apr 8, 2011, at 9:56 AM, Dirk Eddelbuettel wrote:
> Ok, I now committed a slightly nice example to RcppExamples, a package I
> should revamp to contain more examples. In there, we now receive a
> data.frame, operate on each column, create a new data and return old and new.
> The core of the code (inside the try/catch protection) is
> // construct the data.frame object
> Rcpp::DataFrame DF = Rcpp::DataFrame(Dsexp);
> // and access each column by name
> Rcpp::IntegerVector a = DF["a"];
> Rcpp::CharacterVector b = DF["b"];
> Rcpp::DateVector c = DF["c"];
> // do something
> a = 42;
> b = "foo";
> c = c + 7; // move up a week
> // create a new data frame
> Rcpp::DataFrame NDF =
> // and return old and new in list
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel