Description Details Author(s) Examples
View source: R/RcppDataFrame.R
A DataFrame
can be passed C++ and can be instantiated as a
corresponding C++ object using the Rcpp API.
This example shows (in the corresponding C++ code) how to access, modify and create a data frame.
Usage of Rcpp::DataFrame
is fully defined in
the respective header file.
The C++ source file corresponding to the this function does the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // we receive a 'DF' data.frame object
// and access each column by name
Rcpp::IntegerVector a = DF["a"];
Rcpp::CharacterVector b = DF["b"];
Rcpp::DateVector c = DF["c"];
// do something
a[2] = 42;
b[1] = "foo";
c[0] = c[0] + 7; // move up a week
// create a new data frame
Rcpp::DataFrame NDF =
Rcpp::DataFrame::create(Rcpp::Named("a")=a,
Rcpp::Named("b")=b,
Rcpp::Named("c")=c);
// and return old and new in list
return(Rcpp::List::create(Rcpp::Named("origDataFrame")=DF,
Rcpp::Named("newDataFrame")=NDF));
|
Dirk Eddelbuettel and Romain Francois
1 2 3 4 | ## Not run:
RcppDataFrame()
## End(Not run)
|
Original data frame before call:
a b c
1 1 A 2011-01-01
2 2 B 2011-01-02
3 3 C 2011-01-03
After call, original and new data frames:
$origDataFrame
a b c
1 1 A 2011-01-08
2 2 foo 2011-01-02
3 42 C 2011-01-03
$newDataFrame
a b c
1 1 A 2011-01-08
2 2 foo 2011-01-02
3 42 C 2011-01-03
$origDataFrame
a b c
1 1 A 2011-01-08
2 2 foo 2011-01-02
3 42 C 2011-01-03
$newDataFrame
a b c
1 1 A 2011-01-08
2 2 foo 2011-01-02
3 42 C 2011-01-03
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.