DataRange::GetFactorsValues

Description

Get all the factor values as a string array.

Syntax

int GetFactorsValues( DWORD dwRules, int nIndex = 0, vector<string> * pstrFactors = NULL )

Parameters

dwRules
[input] the rules for data extraction, to be taken out of the DRR_ enumeration.
nIndex
[input] the data index whose factors values combination is sought. Not used if pstrFactors us NULL.
pstrFactors
[output] it receives the factors values as strings.

Return

The total number of factors. If *pstrFactors supplied, it equals the size of *pstrFactors.

Examples

EX1

// This example assumes 1 or more columns of main data, 1 or more columns of factor or grouping data, and 1 column of weight data.
// Get the Factor values of the main data and print out the factor, min, max and mean values of the main data in the datarange.
void DataRange_GetFactorsValues_Ex1(int nXColStart = 0, int nXColEnd = 1, int nFColStart = 2, int nFColEnd = 3, int nWCol = 4)
{
    Worksheet wks = Project.ActiveLayer();
    if( wks )
    {
        DWORD dwRules = DRR_GET_MISSING | DRR_BAD_WEIGHT_TREATMENT;
        DataRange dr;
        dr.Add("X", wks, 0, nXColStart, -1, nXColEnd); // Main data
        dr.Add("F", wks, 0, nFColStart, -1, nFColEnd); // Factor data
        dr.Add("W", wks, 0, nWCol, -1, nWCol); // Weight data
        int nNumData = dr.GetNumData(dwRules); //Get the number of data ranges according to the rules dwRules.
        vector<string> vFactors;
        vector vX, vW;
        double dN, dMean, dMax, dMin;
        for( int ii = 0; ii < nNumData; ii++ )
        {
            int nCol = dr.GetData(dwRules, ii, NULL, NULL, &vX, NULL, NULL, NULL, &vW);
            int nNumFactors = dr.GetFactorsValues(dwRules, ii, &vFactors);
            if ( 0 <= nCol )
            {
                vX *= vW;
                dN = vX.GetSize();
                vX.Sum(dMean);
                dMean /= dN;
                vX.GetMinMax(dMin, dMax);
                printf("\nColumn = %s, Factor1 = %s, Factor2 = %s\nMean = %g\nMinimum = %g\nMaximum = %g\n", 
                        wks.Columns(nCol).GetName(), vFactors[0], vFactors[1], dMean, dMin, dMax);
            }
        }
    }
}

Remark

See Also

DataRange::GetNumData, DataRange::GetNumRanges, DataRange::GetData

header to Include

origin.h