var::table
2D array class More...
#include "table.hpp"
Public Functions
Name | |
---|---|
table() Construct a new table object. |
|
table(int r, int c) Construct a new table object. |
|
table(std::initializer_list< std::initializer_list< D >> a) Construct a new table object. |
|
int | row() Get the row size. |
int | col() Get the col size. |
int | size() |
D & | at(int i, int j) Returns reference to element (i, j) |
std::vector< std::string > | get_col_names() Get the col names. |
std::vector< D > | get_col(int j) Get the colum based on index. |
std::vector< D > | get_col(std::string name) Get the column vector based on header name. |
table | get_col_table(int j) Get the col as table |
table | get_col_table(std::string name) Get the col as table |
std::vector< std::string > | get_row_names() Get the row names. |
std::vector< D > | get_row(int i) Get the row based on index. |
std::vector< D > | get_row(std::string name) Get the row vector based on header name. |
table | get_row_table(int i) Get the row as table. |
table | get_row_table(std::string name) Get the row as table. |
void | set_col_names(std::vector< std::string > names) Set the col names. |
void | set_col_name(int j, std::string name) Set the col name. |
void | insert_col(std::vector< D > a, int j, std::string name =std::string()) Inserts new column into given index. |
void | push_col(std::vector< D > a, std::string name =std::string()) Pushes column at the end of the table. |
void | swap_col(int j1, int j2) Swaps two column. |
void | replace_col(int j, std::vector< D > a, std::string name =std::string()) Replaces given column index. |
void | join_col(table other) Combines the columns of another table. |
void | erase_col(int j) Erases given index column. |
void | pop_col() Removes last column. |
void | set_row_names(std::vector< std::string > names) Set the row names. |
void | set_row_name(int i, std::string names) Set the row name. |
void | insert_row(std::vector< D > a, int i, std::string name =std::string()) Inserts new row into given index. |
void | push_row(std::vector< D > a, std::string name =std::string()) Pushes row at the end of the table. |
void | swap_row(int i1, int i2) Swaps two rows. |
void | replace_row(int i, std::vector< D > a, std::string name =std::string()) Replaces given rowumn index. |
void | join_row(table other) Combines the rows of another table. |
void | erase_row(int i) Erases given index rowumn. |
void | pop_row() Removes last rowumn. |
void | resize(int r, int c) Resizes the table. |
void | turn_to(D n) Converts all elements to n. |
D | sum() Sum of all elements. |
bool | read_csv(std::string filename) Reads from csv file. |
bool | save_csv(std::string filename) Reads from csv file. |
void | show(int r) Shows a certain number of rows in table. |
void | show() shows all of the table |
void | show_header() Shows col_names only. |
std::vector< D > | get_avgs() Extract average of each column into a vector. |
std::vector< D > | get_stds() Extract STD of each column into a vector. |
std::vector< D > | get_vars() Extract variance of each column into a vector. |
std::vector< QR< D > > | get_qrs() Extract QR of each column into a vector. |
std::vector< D > | get_sums() Extract sum of each column into a vector. |
table | describe_all() Statistical summary of all colums in table. |
Protected Functions
Name | |
---|---|
int | get_index(int i, int j) Get the index (maps 1D vector to 2D vector) |
int | check_col_name(std::string name) Returns column index of given column name. |
int | check_row_name(std::string name) Returns row index of given row name. |
std::string | generate_line(int l) Generates line to seperate rows. |
void | generate_rows() Clears current row names and generates new ones. |
void | generate_cols() Clears current column names and generates new ones. |
std::string | center(const std::string s, const int w) Re-centers a string based on given width. |
std::string | prd(D x, int width) Fills the string with given width with empty space. |
std::string | prd(std::string x, int width) Gives spacing to a string. |
Protected Attributes
Name | |
---|---|
std::vector< D > | data the data container |
std::vector< std::string > | col_names Stores the column names. |
std::vector< std::string > | row_names Stores the row names. |
int | _row Row size. |
int | _col Colum size. |
int | sz Spacing size for print. |
Detailed Description
template <typename D >
class var::table;
2D array class
Public Functions Documentation
function table
inline table()
Construct a new table object.
- Usage:
var::table<int> t;
function table
inline table(
int r,
int c
)
Construct a new table object.
Parameters:
- r number of rows
- c number of colums
Usage:
var::table<int> t(2, 3); // 2 rows, 3 colums of all 0
function table
inline table(
std::initializer_list< std::initializer_list< D >> a
)
Construct a new table object.
Usage:
var::table<int> m = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
General getters
ainitializer list
function row
inline int row()
Get the row size.
Return: int
function col
inline int col()
Get the col size.
Return: int
function size
inline int size()
function at
inline D & at(
int i,
int j
)
Returns reference to element (i, j)
Column getters
irow index
jcolumn index
D&
element
std::invalid_argumentif invalid indexes
function get_col_names
inline std::vector< std::string > get_col_names()
Get the col names.
Return: std::vector<std::string>