Example 1: TableMultiWay

The same data as 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.

import com.imsl.stat.*;
import com.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);
        System.out.println(); 
        
        TableMultiWay tbl = new TableMultiWay(x,nKeys);
        int ngroups[] = tbl.getGroups();
        System.out.println(" ngroups");
        for (int i=0; i < ngroups.length; i++) 
            System.out.print(ngroups[i] + "  ");                  
    }
}

Output

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


 ngroups
5  1  1  1  
Link to Java source.