I have a list of data frames and I want to loop through the list and within each element in that list (i.e., data frame) loop through the columns to transform that column. The input would look like
$`df1`
a b c
5 30 2
4 2 15
3 2 17
$df2
a b c
5 30 2
4 2 15
3 2 17
and the output would look like:
$`df1`
a b c
5.02 30.02 2
4.15 2.15 15
3.17 2.17 17
$df2
a b c
5.02 30.02 2
4.15 2.15 15
3.17 2.17 17
where the last column, c, is pasted or added (if you take 1/100 of it) to columns a and b in each data frame throughout the list. Note that there might be thousands of these data frames in the list - I just used a list of two data frames as an easy example.
#include <iostream>
#include <fstream>
#include <sstream>
int main() {
std::ifstream fin("input_file");
std::ofstream fout("output_file");
std::string line;
while (fin) {
std::getline(fin, line); // read frame name
fout << line << '\n';
std::getline(fin, line); // read a b c
fout << line << '\n';
for (int i = 0; i < 3; i++) {
std::getline(fin, line);
std::istringstream sin(line);
double a, b, c;
sin >> a >> b >> c;
fout << a + c / 100 << ' '
<< b + c / 100 << ' '
<< c << '\n';
}
std::getline(fin, line); // read blank line
if (fin)
fout << line << '\n';
}
}