peakml.math
Class DataFrame

java.lang.Object
  extended by peakml.math.DataFrame
Direct Known Subclasses:
DataFrame.Double

public abstract class DataFrame
extends java.lang.Object

Convenience implementation of an R-like data-frame, which is essentially a matrix with named rows and columns. It provides specific implementations like DataFrame.Double and DataFrame.Integer for quick and memory efficient storage and access to the data. Complete rows or columns can be retrieved from the matrix for further processing.
When the data-frame is initialized the row- and column-names are initialized to the index of the the row/column.

This class is slated for heavier integration with the Statistical class.


Nested Class Summary
static class DataFrame.Double
          Implementation of the data-frame with the double data-type.
 
Method Summary
 int getColIndexOf(java.lang.String name)
          Returns the index of the column with the given name.
 java.lang.String getColName(int col)
          Returns the name of the column at the given index.
 java.util.Vector<java.lang.String> getColNames()
          Returns a list with all the column-names.
 int getNrColumns()
          Returns the number of columns in the matrix.
 int getNrRows()
          Returns the number of rows in the matrix.
 int getRowIndexOf(java.lang.String name)
          Returns the index of the row with the given name.
 java.lang.String getRowName(int row)
          Returns the name of the row at the given index.
 java.util.Vector<java.lang.String> getRowNames()
          Returns a list with all the row-names.
 void setColName(int col, java.lang.String name)
          Sets the name of the column at the given index.
 void setColNames(java.lang.String... names)
          Sets all the column-names in one step.
 void setColNames(java.util.Vector<java.lang.String> names)
          Sets all the column-names in one step.
 void setRowName(int row, java.lang.String name)
          Sets the name of the row at the given index.
 void setRowNames(java.lang.String... names)
          Sets all the row-names in one step.
 void setRowNames(java.util.Vector<java.lang.String> names)
          Sets all the row-names in one step.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNrRows

public int getNrRows()
Returns the number of rows in the matrix.

Returns:
The number of rows in the matrix.

getRowIndexOf

public int getRowIndexOf(java.lang.String name)
Returns the index of the row with the given name. When the name cannot be found -1 is returned.

Parameters:
name - The name of the row.
Returns:
The index of the row.

getRowName

public java.lang.String getRowName(int row)
                            throws java.lang.IndexOutOfBoundsException
Returns the name of the row at the given index. When the index is smaller than 0 or larger or equal then the number of rows an IndexOutOfBoundsException is thrown.

Parameters:
row - The index of the row.
Returns:
The name of the row at the given index.
Throws:
java.lang.IndexOutOfBoundsException - Thrown when the given index falls outside the range of the number of colomns.

getRowNames

public java.util.Vector<java.lang.String> getRowNames()
Returns a list with all the row-names. The position in the list is equal to the row-index.

Returns:
The list with all the row-names.

setRowName

public void setRowName(int row,
                       java.lang.String name)
                throws java.lang.IndexOutOfBoundsException
Sets the name of the row at the given index.

Parameters:
row - The row index.
name - The new name for the row.
Throws:
java.lang.IndexOutOfBoundsException - Thrown when the given index falls outside the range of the number of rows.

setRowNames

public void setRowNames(java.util.Vector<java.lang.String> names)
                 throws java.lang.RuntimeException
Sets all the row-names in one step. The vector with names needs to be of equal size as the number of rows or otherwise a RuntimeException is thrown.

Parameters:
names - The list with the row-names.
Throws:
java.lang.RuntimeException - Thrown when the list with names is not the same size as the number of rows.

setRowNames

public void setRowNames(java.lang.String... names)
                 throws java.lang.RuntimeException
Sets all the row-names in one step. The array with names needs to be of equal size as the number of rows or otherwise a RuntimeException is thrown.

Parameters:
names - The list with the row-names.
Throws:
java.lang.RuntimeException - Thrown when the list with names is not the same size as the number of rows.

getNrColumns

public int getNrColumns()
Returns the number of columns in the matrix.

Returns:
The number of columns in the matrix.

getColIndexOf

public int getColIndexOf(java.lang.String name)
Returns the index of the column with the given name. When the name cannot be found -1 is returned.

Parameters:
name - The name of the column.
Returns:
The index of the column.

getColName

public java.lang.String getColName(int col)
                            throws java.lang.IndexOutOfBoundsException
Returns the name of the column at the given index. When the index is smaller than 0 or larger or equal then the number of columns an IndexOutOfBoundsException is thrown.

Parameters:
col - The index of the column.
Returns:
The name of the column at the given index.
Throws:
java.lang.IndexOutOfBoundsException - Thrown when the given index falls outside the range of the number of columns.

getColNames

public java.util.Vector<java.lang.String> getColNames()
Returns a list with all the column-names. The position in the list is equal to the column-index.

Returns:
The list with all the column-names.

setColName

public void setColName(int col,
                       java.lang.String name)
Sets the name of the column at the given index.

Parameters:
col - The column index.
name - The new name for the column.
Throws:
java.lang.IndexOutOfBoundsException - Thrown when the given index falls outside the range of the number of columns.

setColNames

public void setColNames(java.util.Vector<java.lang.String> names)
                 throws java.lang.RuntimeException
Sets all the column-names in one step. The vector with names needs to be of equal size as the number of columns or otherwise a RuntimeException is thrown.

Parameters:
names - The list with the column-names.
Throws:
java.lang.RuntimeException - Thrown when the list with names is not the same size as the number of column.

setColNames

public void setColNames(java.lang.String... names)
                 throws java.lang.RuntimeException
Sets all the column-names in one step. The array with names needs to be of equal size as the number of columns or otherwise a RuntimeException is thrown.

Parameters:
names - The list with the column-names.
Throws:
java.lang.RuntimeException - Thrown when the list with names is not the same size as the number of column.