ROOT
v6-26
Reference Guide
Loading...
Searching...
No Matches
DataFrame.C File Reference
Tutorials
»
R tutorials
Detailed Description
void
DataFrame
()
{
using namespace
ROOT::R
;
// Creating variables
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
v1
[0]=1;
v1
[1]=2;
v1
[2]=3;
auto
&
r
= TRInterface::Instance();
// Creating dataframe object with its labels
TRDataFrame
df1(Label[
"var1"
]=
v1
,Label[
"var2"
]=
v2
,Label[
"var3"
]=
v3
,Label[
"strings"
]=names);
// Passing dataframe to R's environment
r
[
"df1"
]<<df1;
r
<<
"print(df1)"
;
// Adding colunms to dataframe
TVectorD
v4
(3);
//filling the vector fro R's environment
r
[
"c(-1,-2,-3)"
]>>
v4
;
//adding new colunm to df1 with name var4
df1[
"var4"
]=
v4
;
//updating df1 in R's environment
r
[
"df1"
]<<df1;
//printing df1
r
<<
"print(df1)"
;
// Getting dataframe from R's environment
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
df2[
"v3"
]<<df1[
"strings"
];
//updating df2 in R's environment
r
[
"df2"
]<<df2;
r
<<
"print(df2)"
;
// Passing values from colunm v3 of df2 to var1 of df1
df2[
"v3"
]>>df1[
"var1"
];
// Updating df1 in R's environment
r
[
"df1"
]<<df1;
r
<<
"print(df1)"
;
}
r
ROOT::R::TRInterface & r
Definition
Object.C:4
DataFrame
void DataFrame()
Definition
DataFrame.C:9
ROOT::R::TRDataFrame
This is a class to create DataFrames from ROOT to R.
Definition
TRDataFrame.h:176
ROOT::R::TRDataFrame::Print
void Print(const Char_t *label="")
Method to print the dataframe in stdout or a column given the label.
Definition
TRDataFrame.h:427
TVectorT< Double_t >
ROOT::R
namespace associated R package for ROOT.
Definition
RExports.h:53
v2
@ v2
Definition
rootcling_impl.cxx:3673
v
@ v
Definition
rootcling_impl.cxx:3670
v4
@ v4
Definition
rootcling_impl.cxx:3675
v3
@ v3
Definition
rootcling_impl.cxx:3674
v1
@ v1
Definition
rootcling_impl.cxx:3672
Author
Definition in file
DataFrame.C
.
tutorials
r
DataFrame.C
ROOT v6-26 - Reference Guide Generated on Mon Sep 11 2023 21:03:23 (GVA Time) using Doxygen 1.9.8