Signature | Description | Parameters |
---|---|---|
template<typename T, typename DF, typename F> std::vector<T> combine(const char *col_name, const DF &rhs, F &functor) const; |
This method combines the content of column col_name between self and rhs based on the logic in functor. Both self and rhs must contain col_name column with the same type as T. It returns the result as a vector that could be moved into one of the dataframes consequently. The length of the result vector will be the min length of the columns in self and rhs. NOTE: It is the responsibility of the user to make sure both columns in self and rhs are properly aligned. |
T: Type on column col_name. If this is index it would be the same as IndexType. DF: Type of the rhs dataframe F: The functor type col_name: Name of the column rhs: An instance of a dataframe that contains the same col_name with the same type (T) functor: An instance of the functor with signature: T func(const T &self_data, const T &rhs_data) |
template<typename T, typename DF1, typename DF2, typename F> std::vector<T> combine(const char *col_name, const DF1 &df1, const DF2 &df2, F &functor) const; |
Same as the combine() above but it combines 3 columns. |
T: Type on column col_name. If this is index it would be the same as IndexType. DF1: Type of the df1 dataframe DF2: Type of the df2 dataframe F: The functor type col_name: Name of the column df1: An instance of a dataframe that contains the same col_name with the same type (T) df2: Another instance of a dataframe that contains the same col_name with the same type (T) functor: An instance of the functor with signature: T func(const T &self_data, const T &df1_data, const T &df2_data) |
template<typename T, typename DF1, typename DF2, typename DF3, typename F> std::vector<T> combine(const char *col_name, const DF1 &df1, const DF2 &df2, const DF3 &df3, F &functor) const; |
Same as the combine() above but it combines 4 columns. |
T: Type on column col_name. If this is index it would be the same as IndexType. DF1: Type of the df1 dataframe DF2: Type of the df2 dataframe DF3: Type of the df3 dataframe F: The functor type col_name: Name of the column df1: An instance of a dataframe that contains the same col_name with the same type (T) df2: Another instance of a dataframe that contains the same col_name with the same type (T) df3: Another instance of a dataframe that contains the same col_name with the same type (T) functor: An instance of the functor with signature: T func(const T &self_data, const T &df1_data, const T &df2_data, const T &df3_data) |
static double my_max(const double &d1, const double &d2, const double &d3) { return (std::max<double>({ d1, d2, d3 })); } static void test_combine() { std::cout << "\nTesting combine( ) ..." << std::endl; std::vector<unsigned long> idx1 = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; std::vector<unsigned long> idx2 = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; std::vector<unsigned long> idx3 = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; std::vector<unsigned long> idx4 = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; std::vector<double> d1 = { 1, 2, 100, 4, 5, 6, 7, 8, 9, 10, 11, 300, 13, 14, 15, 16, 17, 18, 19, 20, 200 }; std::vector<double> d2 = { 1, 2, 1000, 4, 5, 6, 7, 8, 9, 10, 11, 3000, 13, 14, 15, 16, 17, 18, 19, 20, 2000 }; std::vector<double> d3 = { 1, 2, 5000, 4, 5, 6, 7, 8, 9, 10, 11, 7000, 13, 14, 15, 16, 17, 18, 19, 20, 8000 }; std::vector<double> d4 = { 1, 2, 10000, 4, 5, 6, 7, 8, 9, 10, 11, 20000, 13, 14, 15, 16, 17, 18, 19, 20, 30000 }; MyDataFrame df1; MyDataFrame df2; MyDataFrame df3; MyDataFrame df4; df1.load_data(std::move(idx1), std::make_pair("d1_col", d1)); df2.load_data(std::move(idx2), std::make_pair("d1_col", d2)); df3.load_data(std::move(idx3), std::make_pair("d1_col", d3)); df4.load_data(std::move(idx4), std::make_pair("d1_col", d4)); df1.load_column("d2_col", std::move(df1.combine<double>("d1_col", df2, df3, my_max))); std::vector<double> result { 1, 2, 5000, 4, 5, 6, 7, 8, 9, 10, 11, 7000, 13, 14, 15, 16, 17, 18, 19, 20, 8000 }; assert(df1.get_column<double>("d2_col") == result); }