Data Frame

Author:
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, June 23, 2021 at 11:35 AM.

In [ ]:
using namespace ROOT::R;

Creating variables

In [ ]:
TVectorD v1(3);
std::vector<Double_t> v2 {0.101, 0.202, 0.303};
std::array<Int_t,3>  v3{ {1,2,3} };
std::list<std::string> names {"v1", "v2", "v3"};

Assigning values

In [ ]:
v1[0]=1;
v1[1]=2;
v1[2]=3;

auto &r = TRInterface::Instance();

Creating dataframe object with its labels

In [ ]:
TRDataFrame  df1(Label["var1"]=v1,Label["var2"]=v2,Label["var3"]=v3,Label["strings"]=names);

Passing dataframe to r's environment

In [ ]:
r["df1"]<<df1;
r<<"print(df1)";

Adding colunms to dataframe

In [ ]:
TVectorD v4(3);

Filling the vector fro r's environment

In [ ]:
r["c(-1,-2,-3)"]>>v4;

Adding new colunm to df1 with name var4

In [ ]:
df1["var4"]=v4;

Updating df1 in r's environment

In [ ]:
r["df1"]<<df1;

Printing df1

In [ ]:
r<<"print(df1)";

Getting dataframe from r's environment

In [ ]:
TRDataFrame df2;

r<<"df2<-data.frame(v1=c(0.1,0.2,0.3),v2=c(3,2,1))";
r["df2"]>>df2;

TVectorD v(3);
df2["v1"]>>v;
v.Print();

df2["v2"]>>v;
v.Print();

Working with colunms between dataframes

In [ ]:
df2["v3"]<<df1["strings"];

Updating df2 in r's environment

In [ ]:
r["df2"]<<df2;
r<<"print(df2)";

Passing values from colunm v3 of df2 to var1 of df1

In [ ]:
df2["v3"]>>df1["var1"];

Updating df1 in r's environment

In [ ]:
r["df1"]<<df1;
r<<"print(df1)";