Example 2: TableMultiWay

The table of frequencies for a data matrix of size 30 x 2 is output.

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

public class TableMultiWayEx2
{
	public static void  Main(String[] args)
	{
		int[] indkeys = new int[]{0, 1};
		double[,] x = {
				{0.5, 1.5}, {1.5, 3.5},
				{0.5, 3.5}, {1.5, 2.5}, 
				{1.5, 3.5}, {1.5, 4.5},
				{0.5, 1.5}, {1.5, 3.5},
				{3.5, 6.5}, {2.5, 3.5},
				{2.5, 4.5}, {3.5, 6.5}, 
				{1.5, 2.5}, {2.5, 4.5},
				{0.5, 3.5}, {1.5, 2.5},
				{1.5, 3.5}, {0.5, 3.5},
				{0.5, 1.5}, {0.5, 2.5},
				{2.5, 5.5}, {1.5, 2.5},
				{1.5, 3.5}, {1.5, 4.5}, 
				{4.5, 5.5}, {2.5, 4.5},
				{0.5, 3.5}, {1.5, 2.5},
				{0.5, 2.5}, {2.5, 5.5}};
		
		TableMultiWay tbl = new TableMultiWay(x, indkeys);
		
		int[] nvalues = tbl.BalancedTable.GetNvalues();
		
		double[] values = tbl.BalancedTable.GetValues();
		
		Console.Out.WriteLine("          row values");
		for (int i = 0; i < nvalues[0]; i++)
			Console.Out.Write(values[i] + "  ");
		Console.Out.WriteLine("");
		Console.Out.WriteLine("");
		Console.Out.WriteLine("           column values");
		for (int i = 0; i < nvalues[1]; i++)
			Console.Out.Write(values[i + nvalues[0]] + "   ");
		
		double[] table = tbl.BalancedTable.GetTable();
		
		Console.Out.WriteLine("");
		Console.Out.WriteLine("");
		Console.Out.WriteLine("        Table");
		
		
		
		Console.Out.Write("      ");
		for (int i = 0; i < nvalues[1]; i++)
			Console.Out.Write(values[i + nvalues[0]] + "   ");
		Console.Out.WriteLine("");
		for (int i = 0; i < nvalues[0]; i++)
		{
			Console.Out.Write(values[i] + "   ");
			for (int j = 0; j < nvalues[1]; j++)
				Console.Out.Write(table[j + (nvalues[1] * i)] + "   ");
			
			Console.Out.WriteLine(" ");
		}
	}
}

Output

          row values
0.5  1.5  2.5  3.5  4.5  

           column values
1.5   2.5   3.5   4.5   5.5   6.5   

        Table
      1.5   2.5   3.5   4.5   5.5   6.5   
0.5   3   2   4   0   0   0    
1.5   0   5   5   2   0   0    
2.5   0   0   1   3   2   0    
3.5   0   0   0   0   0   2    
4.5   0   0   0   0   1   0    

Link to C# source.