Back to Documentations

Signature Description Parameters
template<comparable T>
StlVecType<char>
in_between(const char *col_name,
           const T &lower_bound,
           const T &upper_bound,
           inclusiveness incld = inclusiveness::begin) const;
This function determines if each item in the named column is between the given lower and upper bounds.
It returns a vector of chars with the same size as the named column. A 0 value means the corresponding element is not between lower and upper bounds. A 1 value means it is.

NOTE: StlVecType is just a std::vector with the applicable allocator for the DataFrame. For example, if you have declared the DataFrame to allocate memory on a particular boundary, then StlVecType is std::vector with an allocator that does so. Otherwise it is just a default std::vector.
T: Type of the named column T must have the comparison operators (== != > < >= <=) well defined
col_name: The name of a column or DF_INDEX_COL_NAME
lower_bound: A lower bound value
upper_bound: An upper bound value
incld: How to include/exclude beginning and end of the bounds
static void test_in_between()  {

    std::cout << "\nTesting in_between( ) ..." << std::endl;

    StlVecType<unsigned long>               idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 };
    StlVecType<std::string>                 s1 = { "XXDnh\1", "XXD974h", "fbbgd", std::string("XXDoiendg\0\0", 11), "yehtfg", "mnbvcd", "dfgsret", "jhnbdfg", "XXDomagdfert", "XXmj;'[-09", "XDimnaxcdf3", "207652234", "XXD", "XX" };
    StlVecType<StlVecType<unsigned char>>   v1 = { { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 8, 9, 10 },
                                                   { 100 },
                                                   { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 100 },
                                                   { 23, 30, 31, 32, 100 } };
    StlVecType<double>                      d3 = { 15, 16, 15, 18, 19, 16, 21, 0.34, 1.56, 0.34, 2.3, 0.34, 19.0, 10 };
    StlVecType<int>                         i1 = { 22, 23, 24, 25, 99 };
    MyDataFrame                             df;

    df.load_data(std::move(idx),
                 std::make_pair("str_col", s1),
                 std::make_pair("col2", v1),
                 std::make_pair("col_3", d3),
                 std::make_pair("col_4", i1));

    {
        const auto  res = df.in_between<double>("col_3", 15.0, 19.0);

        StlVecType<char>    out_res = { 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 };

        assert(res == out_res);
    }

    {
        const auto  res = df.in_between<unsigned long>(DF_INDEX_COL_NAME, 123453, 123460);

        StlVecType<char>    out_res = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };

        assert(res == out_res);
    }

    {
        const auto  res = df.in_between<unsigned long>(DF_INDEX_COL_NAME, 123453, 123460, inclusiveness::end);

        StlVecType<char>    out_res = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 };

        assert(res == out_res);
    }

    {
        const auto  res = df.in_between<unsigned long>(DF_INDEX_COL_NAME, 123453, 123460, inclusiveness::both);

        StlVecType<char>    out_res = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 };

        assert(res == out_res);
    }

    {
        const auto  res = df.in_between<unsigned long>(DF_INDEX_COL_NAME, 123453, 123460, inclusiveness::neither);

        StlVecType<char>    out_res = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };

        assert(res == out_res);
    }
}

C++ DataFrame