2.1.24.4.52 ocu_discrete_frequencies


Description

Function to calculate frequency count for discrete/categorical text data. Frequency is computed for each non-duplicated value of input data.

Syntax

BOOL ocu_discrete_frequencies(StringArray* pocvsSource, StringArray* pocvsData, double* pFreqs, int* pnFreqs, DWORD dwCntrl = 0)

Parameters

pocvsSource
[Input] pointer to a string array containing input text.
pocvsData
[Output] pointer to a string array containing all non-duplucated data from input text.
pFreqs
[Output] pointer to an array containing output frequencies corresponding to the pocvsSource. Size of pFreqs is the size of pocvsSource. Please note that last (nSourceSize-*pnFreqs) values are NANUM;
pnFreqs
[Output] pointer to number of non-duplicated values in input data.
dwCntrl
[Input]The bit controls, default is 0. Including DF_CASE_SENSITIVE(0x01) and DF_TRIM_LEFT_RIGHT_SPACE(0x02).

Return

Return false if the size of source array is 0, else return true.

Examples

EX1 Before running the following code, need keep the second column of current worksheet has string data. For example, import Samples\Statistics\automobile.dat file to an empty worksheet.

#include <ocu.h>
void Ocu_discrete_frequencies()
{
	Worksheet wks = Project.ActiveLayer();
	Column colSource(wks, 1);
	vector<string> vsSource;
	colSource.GetStringArray(vsSource);


	vector<string> vNoDupData;
	vector vFreq(vsSource.GetSize());
	int nFreq;
	if( ocu_discrete_frequencies(&vsSource, &vNoDupData, vFreq, &nFreq) )
	{	
		vFreq.SetSize(nFreq);
		for(int nn = 0; nn < nFreq; nn++)
		{
			printf("%s, %g\n", vNoDupData[nn], vFreq[nn]);
		}
	}
}

Remark

See Also

ocmath_discrete_frequencies, DatasetObject::PercentText

Header to Include

ocu.h

Reference