Documentation
¶
Overview ¶
Package datatable provides a column-centric data structure for aggregating data See https://github.com/Rdatatable/data.table/wiki for inspiration
Index ¶
- Variables
- type Aggregator
- type AggregatorFunc
- type Calculator
- type CalculatorFunc
- type DataTable
- func (dt *DataTable) AddColumn(name string, values []float64) error
- func (dt *DataTable) AddStringColumn(name string, values []string) error
- func (dt *DataTable) Aggregate(colName string, a Aggregator)
- func (dt *DataTable) AggregateIndex(colName string, a Aggregator, indices []int)
- func (dt *DataTable) AggregateIndexFill(col []float64, a Aggregator, indices []int)
- func (dt *DataTable) AggregateWhere(colName string, a Aggregator, m Matcher)
- func (dt *DataTable) Append(dt2 *DataTable) error
- func (dt *DataTable) AppendRow(row []interface{}) error
- func (dt *DataTable) Apply(g Grouper)
- func (dt *DataTable) ApplyIndex(g Grouper, indices []int)
- func (dt *DataTable) ApplyWhere(g Grouper, m Matcher)
- func (dt *DataTable) CSV(w io.Writer) error
- func (dt *DataTable) Calc(colName string, c Calculator)
- func (dt *DataTable) CalcIndex(colName string, c Calculator, indices []int)
- func (dt *DataTable) CalcIndexFill(col []float64, c Calculator, indices []int)
- func (dt *DataTable) CalcWhere(colName string, c Calculator, m Matcher)
- func (dt *DataTable) Clone() *DataTable
- func (dt *DataTable) CloneEmpty() *DataTable
- func (dt *DataTable) CountWhere(m Matcher) int
- func (dt *DataTable) Equal(i, j int) bool
- func (dt *DataTable) KeyNames() []string
- func (dt *DataTable) Len() int
- func (dt *DataTable) Less(i, j int) bool
- func (dt *DataTable) Matches(m Matcher) []int
- func (dt *DataTable) N() int
- func (dt *DataTable) Names() []string
- func (dt *DataTable) ParseRow(values ...string) error
- func (dt *DataTable) RawRows(headers bool) [][]interface{}
- func (dt *DataTable) Reduce(a Aggregator) float64
- func (dt *DataTable) RemoveColumn(name string) error
- func (dt *DataTable) RemoveRows(m Matcher)
- func (dt *DataTable) Row(n int) ([]interface{}, bool)
- func (dt *DataTable) RowMap(n int) (RowMap, bool)
- func (dt *DataTable) RowRef(n int) (RowRef, bool)
- func (dt *DataTable) Rows() RowGroup
- func (dt *DataTable) RowsWhere(m Matcher) RowGroup
- func (dt *DataTable) Select(names []string) (*DataTable, error)
- func (dt *DataTable) SelectIndex(names []string, indices []int) (*DataTable, error)
- func (dt *DataTable) SelectWhere(names []string, m Matcher) (*DataTable, error)
- func (dt *DataTable) SetFloatValue(name string, row int, v float64) error
- func (dt *DataTable) SetKeys(keys ...string) error
- func (dt *DataTable) Swap(i, j int)
- func (dt *DataTable) Unique() *DataTable
- type Grouper
- type GrouperFunc
- type Matcher
- func CloselyEqual(name string, v float64, e float64) Matcher
- func GreaterThan(name string, v float64) Matcher
- func IsEqualString(col string, val string) Matcher
- func IsInf(name string) Matcher
- func IsNan(name string) Matcher
- func IsZero(name string) Matcher
- func LessThan(name string, v float64) Matcher
- func MultiColumnMatcher(m map[string]string) Matcher
- func Not(m Matcher) Matcher
- func NumericColumnMatcher(name string, fn func(float64) bool) Matcher
- func StringColumnMatcher(name string, fn func(string) bool) Matcher
- type MatcherFunc
- type MatchingRowGroup
- func (m *MatchingRowGroup) FloatValue(name string) (float64, bool)
- func (m *MatchingRowGroup) Next() bool
- func (m *MatchingRowGroup) Reset()
- func (m *MatchingRowGroup) RowIndex() int
- func (m *MatchingRowGroup) StringValue(name string) (string, bool)
- func (m *MatchingRowGroup) Value(name string) (interface{}, bool)
- type RowGroup
- type RowMap
- type RowRef
- type StaticRowGroup
- func (r *StaticRowGroup) FloatValue(name string) (float64, bool)
- func (r *StaticRowGroup) Next() bool
- func (r *StaticRowGroup) Reset()
- func (r *StaticRowGroup) RowIndex() int
- func (r *StaticRowGroup) StringValue(name string) (string, bool)
- func (r *StaticRowGroup) Value(name string) (interface{}, bool)
- func (r *StaticRowGroup) Where(m Matcher) *StaticRowGroup
- type Valuer
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Aggregator ¶
func Count ¶
func Count() Aggregator
Count returns an Aggregator that finds the count of numeric values in a group of rows.
func DifferenceOfSums ¶
func DifferenceOfSums(a, b string) Aggregator
func Max ¶
func Max(name string) Aggregator
Max returns an Aggregator that finds the maximum value of a numeric column in a group of rows.
func Mean ¶
func Mean(name string) Aggregator
Mean returns an Aggregator that finds the mean value of a numeric column in a group of rows.
func Min ¶
func Min(name string) Aggregator
Min returns an Aggregator that finds the minimum value of a numeric column in a group of rows.
func RatioOfSums ¶
func RatioOfSums(a, b string) Aggregator
func Sum ¶
func Sum(name string) Aggregator
Sum returns an Aggregator that sums a numeric column in a group of rows.
func Variance ¶
func Variance(name string) Aggregator
Variance returns an Aggregator that finds the variance of a numeric column in a group of rows.
type AggregatorFunc ¶
AggregatorFunc adapts a function to an Aggregator interface
func (AggregatorFunc) Aggregate ¶
func (fn AggregatorFunc) Aggregate(rg RowGroup) float64
type Calculator ¶
A Calculator performs a calculation on a single row of numeric data.
func Constant ¶
func Constant(v float64) Calculator
Constant returns a Calculator that always returns the constant value v
type CalculatorFunc ¶
CalculatorFunc adapts a function to a Calculator interface
func (CalculatorFunc) Calculate ¶
func (fn CalculatorFunc) Calculate(row RowRef) float64
type DataTable ¶
type DataTable struct {
// contains filtered or unexported fields
}
DataTable is a column-centric table of data. Columns can be either numeric (float64) or text (string). A DataTable is not safe for concurrent use.
func (*DataTable) AddColumn ¶
AddColumn adds a column of float64 data. The length of the column must equal the length of any other columns already present in the table.
func (*DataTable) AddStringColumn ¶
AddStringColumn adds a column of string data. The length of the column must equal the length of any other columns already present in the table.
func (*DataTable) Aggregate ¶
func (dt *DataTable) Aggregate(colName string, a Aggregator)
Aggregate appends a new numeric column to the table whose values will be populated by executing the aggregator a against each group of rows that share the same key column values. Each row in a group will be assigned the same value. Rows are evaluated in the table's current sort order as specified by its keys.
func (*DataTable) AggregateIndex ¶
func (dt *DataTable) AggregateIndex(colName string, a Aggregator, indices []int)
AggregateIndex appends a new numeric column to the table whose values will be populated by executing the aggregator a against each group of rows that share the same key column values and are present in indices. Each row in a group will be assigned the same value. Rows are evaluated in the order they appear in indices. Rows not present in indices will be assigned a NaN value in the new column.
func (*DataTable) AggregateIndexFill ¶
func (dt *DataTable) AggregateIndexFill(col []float64, a Aggregator, indices []int)
AggregateIndexFill populates col with values found by executing the aggregator a against each group of rows that share the same key column values and are present in indices. col must be of the same length as the datatable
func (*DataTable) AggregateWhere ¶
func (dt *DataTable) AggregateWhere(colName string, a Aggregator, m Matcher)
AggregateWhere appends a new numeric column to the table whose values will be populated by executing the aggregator a against each group of rows that share the same key column values and match m. Each row in a group will be assigned the same value. Rows are evaluated in the table's current sort order as specified by its keys. Rows not matched by m will be assigned a NaN value in the new column.
func (*DataTable) Append ¶
Append appends the rows of dt2 to the data table. An error is returned if the tables share a column name with differing types (numeric vs text). Columns present in dt but not in dt2 will be expanded to the correct length with either NaN or the empty string. Columns present in dt2 but not dt will be pre-filled with NaN or empty strings before the dt2's data is appened. The data table remains sorted according to its keys after the append.
func (*DataTable) Apply ¶
Apply executes the grouper function g against each group of rows that share the same key column values. Rows are evaluated in the table's current sort order as specified by its keys.
func (*DataTable) ApplyIndex ¶
ApplyIndex executes the grouper function g against each group of rows that share the same key column values and are present in indices. Rows are evaluated in the order they appear in indices.
func (*DataTable) ApplyWhere ¶
ApplyWhere executes the grouper function g against each group of rows that share the same key column values and match m. Rows are evaluated in the table's current sort order as specified by its keys.
func (*DataTable) Calc ¶
func (dt *DataTable) Calc(colName string, c Calculator)
Calc appends a new numeric column to the table whose values will be populated by executing the calculator c against each row of data. Rows are evaluated in the table's current sort order as specified by its keys.
func (*DataTable) CalcIndex ¶
func (dt *DataTable) CalcIndex(colName string, c Calculator, indices []int)
CalcIndex appends a new numeric column to the table whose values will be populated by execting the calculator c against each row of data whose index is contained in indices. Rows are evaluated in the order they appear in indices. Rows not present in indices will be assigned a NaN value in the new column.
func (*DataTable) CalcIndexFill ¶
func (dt *DataTable) CalcIndexFill(col []float64, c Calculator, indices []int)
func (*DataTable) CalcWhere ¶
func (dt *DataTable) CalcWhere(colName string, c Calculator, m Matcher)
CalcWhere appends a new numeric column to the table whose values will be populated by execting the calculator c against each row of data that matches m. Rows are evaluated in the table's current sort order as specified by its keys. Rows not matched by m will be assigned a NaN value in the new column.
func (*DataTable) Clone ¶
Clone returns a new data table containing copies of the columns contained in dt. The returned data table will have no keys set.
func (*DataTable) CloneEmpty ¶
CloneEmpty creates an identical but empty data table with no keys set.
func (*DataTable) CountWhere ¶
CountWhere counts the number of rows that match m. Rows are evaluated in the table's current sort order as specified by its keys.
func (*DataTable) Equal ¶
Equal compares two rows and returns whether they contain the same values. If the table has keys specified then only those columns will be used in the comparison, in the order specified by the keys. Otherwise all columns are compared in the order they were added to the table.
func (*DataTable) Less ¶
Less compares two rows and returns whether the row with index i should sort before the row at index j. If the table has keys specified then only those columns will be used in the comparison, in the order specified by the keys. Otherwise all columns are compared in the order they were added to the table.
func (*DataTable) Names ¶
Names returns a slice of the column names in the data table in the order the columns were added to the table.
func (*DataTable) ParseRow ¶
ParseRow attempts to append a row of data by parsing values as either float64 or string depending on the existing type of the relevant column. Values are processed in the order that columns were added to the table.
func (*DataTable) RawRows ¶
RawRows returns all the rows in the datatable. If headers is true then the first row returned will contain the column names. Values in each row are in the order the column was added to the table.
func (*DataTable) Reduce ¶
func (dt *DataTable) Reduce(a Aggregator) float64
Reduce returns the value obtained by executing the aggregator a against each row in the datatable.
func (*DataTable) RemoveColumn ¶
RemoveColumn removes a column of any type from the data table.
func (*DataTable) RemoveRows ¶
RemoveRows removes any rows that match m without altering their order.
func (*DataTable) Row ¶
Row returns a single row of data as a slice or an empty slice and false if the row number exceed the bounds of the table. The returned slice contains one value per column in the order the columns were added to the table.
func (*DataTable) RowMap ¶
RowMap returns a single row of data as a map or an empty map and false if the row number exceed the bounds of the table. The keys in the returned map correspond to the names of the columns.
func (*DataTable) Select ¶
Select returns a new data table containing copies of the columns specified in names. The returned data table will have no keys set.
func (*DataTable) SelectIndex ¶
SelectIndex returns a new data table containing copies of the columns specified in names where the rows are in indices. The returned data table will have no keys set.
func (*DataTable) SelectWhere ¶
SelectWhere returns a new data table containing copies of the columns specified in names where the rows match m. The returned data table will have no keys set.
func (*DataTable) SetFloatValue ¶
func (*DataTable) SetKeys ¶
SetKeys assigns a set of column names to be used as keys when sorting or aggregating. Setting keys sorts the table immediately by the specified keys.
type Grouper ¶
type Grouper interface {
Group(rg RowGroup)
}
A Grouper performs an action given a group of rows.
type GrouperFunc ¶
type GrouperFunc func(rg RowGroup)
GrouperFunc adapts a function to a Grouper interface
func (GrouperFunc) Group ¶
func (fn GrouperFunc) Group(rg RowGroup)
type Matcher ¶
A Matcher tests a single row of data to determine whether it matches a particular set of criteria.
func CloselyEqual ¶
CloselyEqual returns a Matcher that tests whether the named column is equal to v within the range +/- e
func GreaterThan ¶
GreaterThan returns a Matcher that tests whether the named column is greater than v or not
func IsEqualString ¶
IsEqualString returns a Matcher that tests whether the named column is equal to the given string
func IsInf ¶
IsInf returns a Matcher that tests whether the named column is infinite (either positive or negative infinity will return true).
func LessThan ¶
LessThan returns a Matcher that tests whether the named column is less than v or not
func MultiColumnMatcher ¶
MultiColumnMatcher returns a Matcher that tests whether the a rown matches the names and values in the map m
func NumericColumnMatcher ¶
NumericColumnMatcher returns a Matcher that tests the value of a single column in a row of data against the numeric function fn.
type MatcherFunc ¶
MatcherFunc adapts a function to a Matcher interface
func (MatcherFunc) Match ¶
func (fn MatcherFunc) Match(row RowRef) bool
type MatchingRowGroup ¶
type MatchingRowGroup struct {
// contains filtered or unexported fields
}
func (*MatchingRowGroup) FloatValue ¶
func (m *MatchingRowGroup) FloatValue(name string) (float64, bool)
func (*MatchingRowGroup) Next ¶
func (m *MatchingRowGroup) Next() bool
func (*MatchingRowGroup) Reset ¶
func (m *MatchingRowGroup) Reset()
func (*MatchingRowGroup) RowIndex ¶
func (m *MatchingRowGroup) RowIndex() int
func (*MatchingRowGroup) StringValue ¶
func (m *MatchingRowGroup) StringValue(name string) (string, bool)
func (*MatchingRowGroup) Value ¶
func (m *MatchingRowGroup) Value(name string) (interface{}, bool)
type StaticRowGroup ¶
type StaticRowGroup struct {
// contains filtered or unexported fields
}
func (*StaticRowGroup) FloatValue ¶
func (r *StaticRowGroup) FloatValue(name string) (float64, bool)
func (*StaticRowGroup) Next ¶
func (r *StaticRowGroup) Next() bool
func (*StaticRowGroup) Reset ¶
func (r *StaticRowGroup) Reset()
func (*StaticRowGroup) RowIndex ¶
func (r *StaticRowGroup) RowIndex() int
RowIndex returns the datatable index of the current row in the row group. It is an error if this is called before calling Next and the function will panic.
func (*StaticRowGroup) StringValue ¶
func (r *StaticRowGroup) StringValue(name string) (string, bool)
func (*StaticRowGroup) Value ¶
func (r *StaticRowGroup) Value(name string) (interface{}, bool)
func (*StaticRowGroup) Where ¶
func (r *StaticRowGroup) Where(m Matcher) *StaticRowGroup
Where applies a matcher to the rows in this row group, returning a new row group that contains only the rows that matched. It does not affect the current position of r's iteration.