Example 3: TableMultiWay

The unbalanced table of frequencies for a data matrix of size 4 x 3 is output.

import com.imsl.stat.*;
import com.imsl.math.*;

public class TableMultiWayEx3 {   
    public static void main(String args[]) {
        int    indkeys[] = {0,1};
        double x[][] = {
            {2.0, 5.0, 1.0}, {1.0, 5.0, 2.0},
            {1.0, 6.0, 3.0}, {2.0, 6.0, 4.0}
        };
        double frq[] = {1.0, 2.0, 3.0, 4.0};
        
        TableMultiWay tbl = new TableMultiWay(x,indkeys);
        tbl.setFrequencies(frq);
        
        int ncells = tbl.getUnbalancedTable().getNCells();
        double listCells[] = tbl.getUnbalancedTable().getListCells();
        double table[] = tbl.getUnbalancedTable().getTable();
        
        PrintMatrix pm = new PrintMatrix("List Cells");
        PrintMatrixFormat mf = new PrintMatrixFormat();
        mf.setNoRowLabels();
        mf.setNoColumnLabels();
        //	Print the array
        pm.print(mf, listCells);
        System.out.println();
        
        pm = new PrintMatrix("Unbalanced Table");
        mf = new PrintMatrixFormat();
        mf.setNoRowLabels();
        mf.setNoColumnLabels();
        //	Print the array
        pm.print(mf, table);
        System.out.println();
    } 
}

Output

List Cells
     
1  
5  
1  
6  
2  
5  
2  
6  


Unbalanced Table
     
2  
3  
1  
4  


Link to Java source.