private static Object[] convertToColumns(Object[][] data){
  Object[] row=data[0];
  int nrow=data.length;
  Object[] results=new Object[row.length];
  for (int col=0; col < row.length; col++) {
    if (row[col] instanceof String) {
      String[] sa=new String[nrow];
      for (int irow=0; irow < nrow; irow++) {
        sa[irow]=(String)data[irow][col];
      }
      results[col]=sa;
    }
 else {
      Class<?> base=ArrayFuncs.getBaseClass(row[col]);
      int[] dims=ArrayFuncs.getDimensions(row[col]);
      if (dims.length > 1 || dims[0] > 1) {
        int[] xdims=new int[dims.length + 1];
        xdims[0]=nrow;
        Object[] arr=(Object[])ArrayFuncs.newInstance(base,xdims);
        for (int irow=0; irow < nrow; irow++) {
          arr[irow]=data[irow][col];
        }
        results[col]=arr;
      }
 else {
        Object arr=ArrayFuncs.newInstance(base,nrow);
        for (int irow=0; irow < nrow; irow++) {
          System.arraycopy(data[irow][col],0,arr,irow,1);
        }
        results[col]=arr;
      }
    }
  }
  return results;
}

private static Object [ ] convertToColumns ( Object [ ] [ ] data ) { Object [ ] row = data [ 0 ] ; int nrow = data . length ; Object [ ] results = new Object [ row . length ] ; for ( int col = 0 ; col < row . length ; col ++ ) { if ( row [ col ] instanceof String ) { String [ ] sa = new String [ nrow ] ; for ( int irow = 0 ; irow < nrow ; irow ++ ) { sa [ irow ] = ( String ) data [ irow ] [ col ] ; } results [ col ] = sa ; } else { Class < ? > base = ArrayFuncs . getBaseClass ( row [ col ] ) ; int [ ] dims = ArrayFuncs . getDimensions ( row [ col ] ) ; if ( dims . length > 1 || dims [ 0 ] > 1 ) { int [ ] xdims = new int [ dims . length + 1 ] ; xdims [ 0 ] = nrow ; Object [ ] arr = ( Object [ ] ) ArrayFuncs . newInstance ( base , xdims ) ; for ( int irow = 0 ; irow < nrow ; irow ++ ) { arr [ irow ] = data [ irow ] [ col ] ; } results [ col ] = arr ; } else { Object arr = ArrayFuncs . newInstance ( base , nrow ) ; for ( int irow = 0 ; irow < nrow ; irow ++ ) { System . arraycopy ( data [ irow ] [ col ] , 0 , arr , irow , 1 ) ; } results [ col ] = arr ; } } } return results ; }
convert a two - d table to a table of columns . handle string specially . every other element of data should be a primitive array of some dimensionality . basically the translates a table expressed as objects in row order to a table with objects in column order .
