I’m looking to be able to use the Foreach method of RDataFrame to be able to modify a preexisting column in a dataframe.
As a test, I have tried:
ROOT::RDataFrame df(10);
auto d_new = df.Define("x","0");
d_new.Foreach([](int x){ cout << x << endl; },{"x"}); //prints 0s
d_new.Foreach([](int &x){ x = 7; },{"x"});
d_new.Foreach([](int x){ cout << x << endl; },{"x"}); //still prints 0s
but this does not give the desired behaviour, the columns remain unchanged.
Is there any way of modifying columns like this?
My use case is to be able to define multiple columns at once, for quantities that are correlated and will share much of the same calculation. The best way I have found to be able to do this is to have a function which returns multiple values, and then call that from lambdas inside define statements, selecting the values that are necessary for that particular definition. The obvious issue with this is the code which calculates all the values is run every time a new quantity is defined. Also, I feel it makes the code rather messy.