Skip to content

Instantly share code, notes, and snippets.

@ifknot
Last active September 5, 2020 19:00
Show Gist options
  • Save ifknot/161bbed10fde1adb3bd5527c5b98fb20 to your computer and use it in GitHub Desktop.
Save ifknot/161bbed10fde1adb3bd5527c5b98fb20 to your computer and use it in GitHub Desktop.
#include <iostream>
#include "r_data_frame.h"
int main() {
std::cout << "heterogeneous container\n\n";
R::data_frame d;
d["id"] = { 1, 2, 3, 4, 5 };
d["name"] = { "Rick", "Dan", "Michelle", "Ryan", "Gary" };
d["salary"] = { 623.3, 515.2, 611.0, 729.0, 843.25 };
d["start_date"] = R::as_dates({ "2012-01-01", "2013-09-23", "2014-11-15", "2014-05-11", "2015-03-27" });
// print out data table
std::cout << d << '\n';
// accessing data does need prior knowledge of the column data type
auto money = std::get<double>(d["salary"][1]);
// but C++ is strongly typed so there we go
std::cout << std::get<std::string>(d["name"][1]) << " earns $" << money << "\n\n";
std::cout << d["name"] << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment