Example 1: TableMultiWay

The same data used in SortEx2 is used in this example. It is a 10 x 3 matrix using Columns 0 and 1 as keys. There are two missing values (NaNs) in the keys. NaN is displayed as a ?. Table MultiWay determines the number of groups of different observations.

using System;
using Imsl.Stat;
using Imsl.Math;

public class TableMultiWayEx1
{
	public static void  Main(String[] args)
	{
		int nKeys = 2;
		double[,] x = {
			{1.0, 1.0, 1.0}, {2.0, 1.0, 2.0},
			{1.0, 1.0, 3.0}, {1.0, 1.0, 4.0},
			{2.0, 2.0, 5.0}, {1.0, 2.0, 6.0},
			{1.0, 2.0, 7.0}, {1.0, 1.0, 8.0},
			{2.0, 2.0, 9.0}, {1.0, 1.0, 9.0}};
		
		x[4,1] = Double.NaN;
		x[6,0] = Double.NaN;
		
		PrintMatrix pm = new PrintMatrix("The Input Array");
		PrintMatrixFormat mf = new PrintMatrixFormat();
		mf.SetNoRowLabels();
		mf.SetNoColumnLabels();
		//	Print the array
		pm.Print(mf, x);
		Console.Out.WriteLine();
		
		TableMultiWay tbl = new TableMultiWay(x, nKeys);
		int[] ngroups = tbl.GetGroups();
		Console.Out.WriteLine(" ngroups");
		for (int i = 0; i < ngroups.Length; i++)
			Console.Out.Write(ngroups[i] + "  ");
	}
}

Output

The Input Array
               
1    1    1  
2    1    2  
1    1    3  
1    1    4  
2    NaN  5  
1    2    6  
NaN  2    7  
1    1    8  
2    2    9  
1    1    9  


 ngroups
5  1  1  1  
Link to C# source.