bpp-core3
3.0.0
|
This class corresponds to a 'dataset', i.e. a table with data by rows and variable by columns. More...
#include <Bpp/Numeric/Table.h>
Public Member Functions | |
Table (size_t nRow, size_t nCol) | |
Build a new void Table object with nRow rows and nCol columns. More... | |
Table (const std::vector< std::string > &colNames) | |
Build a new void Table object with named columns. More... | |
Table (const Table &table) | |
Table (const std::vector< std::vector< T >> &vt) | |
Table & | operator= (const Table &table) |
Table & | operator= (const std::vector< std::vector< T >> &vt) |
Table * | clone () const |
Create a copy of this object and send a pointer to it. More... | |
virtual | ~Table () |
const std::vector< std::vector< T > > & | getData () const |
T & | operator() (size_t rowIndex, size_t colIndex) |
const T & | operator() (size_t rowIndex, size_t colIndex) const |
T & | operator() (const std::string &rowName, const std::string &colName) |
const T & | operator() (const std::string &rowName, const std::string &colName) const |
T & | operator() (const std::string &rowName, size_t colIndex) |
const T & | operator() (const std::string &rowName, size_t colIndex) const |
T & | operator() (size_t rowIndex, const std::string &colName) |
const T & | operator() (size_t rowIndex, const std::string &colName) const |
Work on columns. | |
size_t | getNumberOfColumns () const |
void | setColumnNames (const std::vector< std::string > &colNames) |
Set the column names of this table. More... | |
const std::vector< std::string > & | getColumnNames () const |
Get the column names of this table. More... | |
std::vector< std::string > & | getColumnNames () |
std::string | getColumnName (size_t index) const |
Get a given column name. More... | |
bool | hasColumnNames () const |
std::vector< T > & | getColumn (size_t index) |
const std::vector< T > & | getColumn (size_t index) const |
std::vector< T > & | getColumn (const std::string &colName) |
const std::vector< T > & | getColumn (const std::string &colName) const |
bool | hasColumn (const std::string &colName) const |
Tell is a given column exists. More... | |
void | deleteColumn (size_t index) |
Delete the given column. More... | |
void | deleteColumns (size_t index, size_t len) |
Delete the given columns. More... | |
void | deleteColumn (const std::string &colName) |
Delete the given column. More... | |
void | addColumn (const std::vector< T > &newColumn, int pos=-1) |
Add a new column. More... | |
void | addColumn (const std::string &colName, const std::vector< T > &newColumn, int pos=-1) |
Add a new column. More... | |
void | addColumn (std::string &st, const std::string &sep="\, int pos=-1, int rowCol=-1) |
Add a new column. More... | |
void | setColumn (const std::vector< T > &newColumn, size_t pos) |
Set a new column. More... | |
void | setColumn (const std::string &colName, const std::vector< T > &newColumn, size_t pos) |
Set a new column. More... | |
Work on rows. | |
size_t | getNumberOfRows () const |
void | setRowNames (const std::vector< std::string > &rowNames) |
Set the row names of this table. More... | |
std::vector< std::string > | getRowNames () |
Get the row names of this table. More... | |
const std::vector< std::string > & | getRowNames () const |
bool | hasRow (const std::string &rowName) const |
Tell is a given row exists. More... | |
std::string | getRowName (size_t index) const |
Get a given row name. More... | |
bool | hasRowNames () const |
std::vector< T > | getRow (size_t index) const |
std::vector< T > | getRow (const std::string &rowName) const |
void | deleteRow (size_t index) |
Delete the given row. More... | |
void | deleteRows (size_t index, size_t len) |
Delete the given rows. More... | |
void | deleteRow (const std::string &rowName) |
Delete the given row. More... | |
void | addRow (const std::vector< T > &newRow, int pos=-1) |
Add a new row. More... | |
void | addRow (const std::string &rowName, const std::vector< T > &newRow, int pos=-1) |
Add a new row at a given position. More... | |
void | addRow (std::string &st, const std::string &sep="\, int pos=-1, int rowCol=-1) |
Add a new row. More... | |
Static Public Member Functions | |
static std::unique_ptr< Table< T > > | read (std::istream &in, bool byRow, const std::string &sep="\, bool header=true, int names=-1) |
Read a table form a stream in CSV-like. More... | |
static void | write (const Table &data, std::ostream &out, bool byRow, const std::string &sep="\, bool alignHeaders=false) |
Write a Table object to stream in CSV-like format. More... | |
static void | write (const Table &data, bpp::OutputStream &out, bool byRow, const std::string &sep="\, bool alignHeaders=false) |
Protected Attributes | |
size_t | nRow_ |
size_t | nCol_ |
std::vector< std::vector< T > > | data_ |
std::vector< std::string > | rowNames_ |
std::vector< std::string > | colNames_ |
This class corresponds to a 'dataset', i.e. a table with data by rows and variable by columns.
Data are stored as T objects, by column.
|
inline |
|
inline |
Build a new void Table object with named columns.
colNames | The names of the columns of the Table. |
DuplicatedTableColumnNameException | If colnames contains identical names. |
Definition at line 67 of file Table.h.
References bpp::Table< T >::setColumnNames().
|
inline |
|
inline |
|
inlinevirtual |
|
inline |
Add a new column.
newColumn | The new column values. |
pos | The position optional (default : -1 for nb columns) |
DimensionException | If the number of values does not match the number of rows. |
TableColumnNamesException | If the table has row names. |
Definition at line 554 of file Table.h.
References bpp::Table< T >::nRow_.
|
inline |
Add a new column.
colName | The name of the column. |
newColumn | The new column values. |
pos | The position optional (default : -1 for nb columns) |
DimensionException | If the number of values does not match the number of rows. |
NoTableColumnNamesException | If the table does not have row names. |
DuplicatedTableColumnNameException | If colName is already used. |
Definition at line 580 of file Table.h.
References bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.
|
inline |
Add a new column.
st | the input sting |
sep | The row delimiter |
pos | The position optional (default : nb cols) |
rowCol | the indice of row where colnames are, starting from 0 (default -1 means no such column) |
Definition at line 609 of file Table.h.
References bpp::StringTokenizer::getTokens().
|
inline |
Add a new row.
newRow | The new row values. |
pos | The position optional (default : -1 for nb rows) |
Definition at line 916 of file Table.h.
References bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.
|
inline |
Add a new row at a given position.
rowName | The name of the row. |
newRow | The new row values. |
pos | The position optional (default : -1 for nb rows) |
Definition at line 942 of file Table.h.
References bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.
|
inline |
Add a new row.
st | the input string |
sep | The column delimiter |
pos | The position optional (default : nb rows) |
rowCol | the indice of column where rownames are, starting from 0 (default -1 means no such column) |
Definition at line 973 of file Table.h.
References bpp::StringTokenizer::getTokens().
|
inlinevirtual |
Create a copy of this object and send a pointer to it.
Implements bpp::Clonable.
Definition at line 123 of file Table.h.
References bpp::Table< T >::Table().
|
inline |
Delete the given column.
index | The index of the column. |
IndexOutOfBoundsException | If index is >= number of columns. |
|
inline |
Delete the given column.
colName | The name of the column. |
NoTableColumnNamesException | If no column names are associated to this table. |
TableColumnNameNotFoundException | If colName do not match existing column names. |
Definition at line 528 of file Table.h.
References bpp::VectorTools::which().
|
inline |
Delete the given columns.
index | The index of the first column |
len | the number of columns to delete |
IndexOutOfBoundsException | If index is >= number of columns. |
|
inline |
Delete the given row.
index | The index of the row. |
IndexOutOfBoundsException | If index is >= number of row. |
Definition at line 845 of file Table.h.
References bpp::Table< T >::nCol_.
|
inline |
Delete the given row.
rowName | The name of the row. |
NoTableRowNamesException | If no row names are associated to this table. |
TableRowNameNotFoundException | If rowName do not match existing column names. |
Definition at line 888 of file Table.h.
References bpp::Table< T >::nCol_, and bpp::VectorTools::which().
|
inline |
Delete the given rows.
index | The index of the first row. |
len | the number of rows to delete |
IndexOutOfBoundsException | If index is >= number of row. |
Definition at line 866 of file Table.h.
References bpp::Table< T >::nCol_.
|
inline |
index | The index of the column. |
IndexOutOfBoundsException | If index is >= number of columns. |
|
inline |
index | The index of the column. |
IndexOutOfBoundsException | If index is >= number of columns. |
|
inline |
colName | The name of the column. |
NoTableColumnNamesException | If no column names are associated to this table. |
TableColumnNameNotFoundException | If colName do not match existing column names. |
Definition at line 428 of file Table.h.
References bpp::VectorTools::which().
|
inline |
colName | The name of the column. |
NoTableColumnNamesException | If no column names are associated to this table. |
TableColumnNameNotFoundException | If colName do not match existing column names. |
Definition at line 449 of file Table.h.
References bpp::VectorTools::which().
|
inline |
Get a given column name.
index | The index of the column. |
NoTableColumnNamesException | If no column names are associated to this table. |
IndexOutOfBoundsException | If index is >= number of columns. |
Definition at line 382 of file Table.h.
Referenced by bpp::Table< T >::write().
|
inline |
Get the column names of this table.
NoTableColumnNamesException | If no column names are associated to this table. |
Definition at line 360 of file Table.h.
References bpp::Table< T >::colNames_.
Referenced by bpp::Table< T >::write().
|
inline |
Definition at line 367 of file Table.h.
References bpp::Table< T >::colNames_.
|
inline |
|
inline |
Definition at line 334 of file Table.h.
References bpp::Table< T >::nCol_.
Referenced by bpp::Table< T >::write().
|
inline |
Definition at line 707 of file Table.h.
References bpp::Table< T >::nRow_.
Referenced by bpp::Table< T >::write().
|
inline |
index | The index of the row. |
IndexOutOfBoundsException | If index is >= number of rows. |
Definition at line 799 of file Table.h.
References bpp::Table< T >::nCol_.
|
inline |
rowName | The name of the row. |
NoTableRowNamesException | If no row names are associated to this table. |
TableRowNameNotFoundException | If rowName do not match existing row names. |
Definition at line 818 of file Table.h.
References bpp::Table< T >::nCol_, and bpp::VectorTools::which().
|
inline |
Get a given row name.
index | The index of the row. |
NoTableRowNamesException | If no row names are associated to this table. |
IndexOutOfBoundsException | If index is >= number of rows. |
Definition at line 779 of file Table.h.
Referenced by bpp::Table< T >::write().
|
inline |
Get the row names of this table.
NoTableRowNamesException | If no row names are associated to this table. |
Definition at line 737 of file Table.h.
References bpp::Table< T >::rowNames_.
Referenced by bpp::Table< T >::write().
|
inline |
Definition at line 744 of file Table.h.
References bpp::Table< T >::rowNames_.
|
inline |
|
inline |
Definition at line 395 of file Table.h.
Referenced by bpp::Table< T >::write().
|
inline |
|
inline |
Definition at line 792 of file Table.h.
Referenced by bpp::Table< T >::write().
|
inline |
rowIndex | Row number. |
colIndex | Column number. |
IndexOutOfBoundsException | If one of the index is greater or equal to the corresponding number of columns/rows. |
|
inline |
rowIndex | Row number. |
colIndex | Column number. |
IndexOutOfBoundsException | If one of the index is greater or equal to the corresponding number of columns/rows. |
|
inline |
rowName | Row name. |
colName | Column name. |
NoTableRowNamesException | If the table does not have names associated to rows. |
NoTableColumnNamesException | If the table does not have names associated to columns. |
TableNameNotFoundException | If one of rowName or colName do not match existing names. |
Definition at line 176 of file Table.h.
References bpp::ElementNotFoundException< T >::getElement(), and bpp::VectorTools::which().
|
inline |
rowName | Row name. |
colName | Column name. |
NoTableRowNamesException | If the table does not have names associated to rows. |
NoTableColumnNamesException | If the table does not have names associated to columns. |
TableNameNotFoundException | If one of rowName or colName do not match existing names. |
Definition at line 203 of file Table.h.
References bpp::ElementNotFoundException< T >::getElement(), and bpp::VectorTools::which().
|
inline |
rowName | Row name. |
colIndex | Column number. |
NoTableRowNamesException | If the table does not have names associated to rows. |
IndexOutOfBoundsException | If the index is greater or equal to the number of columns. |
TableNameNotFoundException | If rowName do not match existing names. |
Definition at line 230 of file Table.h.
References bpp::ElementNotFoundException< T >::getElement(), and bpp::VectorTools::which().
|
inline |
rowName | Row name. |
colIndex | Column number. |
NoTableRowNamesException | If the table does not have names associated to rows. |
IndexOutOfBoundsException | If the index is greater or equal to the number of columns. |
TableNameNotFoundException | If rowName do not match existing names. |
Definition at line 256 of file Table.h.
References bpp::ElementNotFoundException< T >::getElement(), and bpp::VectorTools::which().
|
inline |
rowIndex | Row number. |
colName | Column name. |
IndexOutOfBoundsException | If the index is greater or equal to the number of rows. |
NoTableColumnNamesException | If the table does not have names associated to columns. |
TableNameNotFoundException | If colName do not match existing names. |
Definition at line 282 of file Table.h.
References bpp::ElementNotFoundException< T >::getElement(), and bpp::VectorTools::which().
|
inline |
rowIndex | Row number. |
colName | Column name. |
IndexOutOfBoundsException | If the index is greater or equal to the number of rows. |
NoTableColumnNamesException | If the table does not have names associated to columns. |
TableNameNotFoundException | If colName do not match existing names. |
Definition at line 308 of file Table.h.
References bpp::ElementNotFoundException< T >::getElement(), and bpp::VectorTools::which().
|
inline |
Definition at line 94 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.
|
inline |
|
inlinestatic |
Read a table form a stream in CSV-like.
By default, if the first line as one column less than the second one, the first line is taken as column names, and the first column as row names. Otherwise, no column names and no row names are specified, unless explicitely precised by the user. Note: if byRow=false, exchange row and column roles.
in | The input stream. |
byRow | Tell if the table is filled by rows |
sep | The line delimiter. |
header | Tell if the first line must be used for names, otherwise use default. |
names | Use a column as rowNames (or a row as columnNames). If positive, use the specified column to compute rownames, otherwise use default; |
Definition at line 1031 of file Table.h.
References bpp::FileTools::getNextLine(), bpp::StringTokenizer::getTokens(), and bpp::TextTools::isEmpty().
|
inline |
Set a new column.
newColumn | The new column values. |
pos | The position |
DimensionException | If the number of values does not match the number of rows. |
TableColumnNamesException | If the table has row names. |
Definition at line 656 of file Table.h.
References bpp::Table< T >::nRow_.
|
inline |
Set a new column.
colName | The name of the column. |
newColumn | The new column values. |
pos | The position |
DimensionException | If the number of values does not match the number of rows. |
NoTableColumnNamesException | If the table does not have row names. |
DuplicatedTableColumnNameException | If colName is already used. |
Definition at line 677 of file Table.h.
References bpp::Table< T >::nRow_.
|
inline |
Set the column names of this table.
colNames | The row names. |
DimensionException | If the number of names do not match the number of columns in the table. |
DuplicatedTableColumnNameException | If names are not unique. |
Definition at line 343 of file Table.h.
References bpp::VectorTools::isUnique(), and bpp::Table< T >::nCol_.
Referenced by bpp::Table< T >::Table().
|
inline |
Set the row names of this table.
rowNames | The row names. |
DimensionException | If the number of names do not match the number of rows in the table. |
DuplicatedTableRowNameException | If names are not unique. |
Definition at line 716 of file Table.h.
References bpp::VectorTools::isUnique(), and bpp::Table< T >::nRow_.
|
inlinestatic |
Write a Table object to stream in CSV-like format.
data | The table to write. |
out | The output stream. |
byRow | Tell if the table is written by rows. |
sep | The column delimiter. |
alignHeaders | If true, add a delimiter before the first column header if there is row names. |
Definition at line 1092 of file Table.h.
References bpp::Table< T >::getColumnName(), bpp::Table< T >::getColumnNames(), bpp::Table< T >::getNumberOfColumns(), bpp::Table< T >::getNumberOfRows(), bpp::Table< T >::getRowName(), bpp::Table< T >::getRowNames(), bpp::Table< T >::hasColumnNames(), and bpp::Table< T >::hasRowNames().
|
inlinestatic |
Definition at line 1133 of file Table.h.
References bpp::OutputStream::endLine(), bpp::Table< T >::getColumnName(), bpp::Table< T >::getColumnNames(), bpp::Table< T >::getNumberOfColumns(), bpp::Table< T >::getNumberOfRows(), bpp::Table< T >::getRowName(), bpp::Table< T >::getRowNames(), bpp::Table< T >::hasColumnNames(), and bpp::Table< T >::hasRowNames().
|
protected |
Definition at line 37 of file Table.h.
Referenced by bpp::Table< T >::getColumnNames(), and bpp::Table< T >::operator=().
|
protected |
Definition at line 35 of file Table.h.
Referenced by bpp::Table< T >::getData(), and bpp::Table< T >::operator=().
|
protected |
Definition at line 34 of file Table.h.
Referenced by bpp::Table< T >::addColumn(), bpp::Table< T >::addRow(), bpp::Table< T >::deleteRow(), bpp::Table< T >::deleteRows(), bpp::Table< T >::getNumberOfColumns(), bpp::Table< T >::getRow(), bpp::Table< T >::operator=(), and bpp::Table< T >::setColumnNames().
|
protected |
Definition at line 34 of file Table.h.
Referenced by bpp::Table< T >::addColumn(), bpp::Table< T >::addRow(), bpp::Table< T >::getNumberOfRows(), bpp::Table< T >::operator=(), bpp::Table< T >::setColumn(), and bpp::Table< T >::setRowNames().
|
protected |
Definition at line 36 of file Table.h.
Referenced by bpp::Table< T >::getRowNames(), and bpp::Table< T >::operator=().