- Index
- »
- axon
- »
- func:foldCols
def
func:foldCols
foldCols(grid, colSelector, newColName, fn)
Fold a set of columns in each row into a new folded column and return a new grid. The columns to fold are selected by the colSelector
function and removed from the result. The selector may be a list of string names or a function which takes a Col and returns true to select it. The folding function uses same semantics as fold()
.
Example:
// consider grid 'g' with the following structure: a b c --- --- --- 1 10 100 2 20 200 // foldCols, add b and c together to create new bc column g.foldCols(["b", "c"], "bc", sum) // yields this grid: a bc --- --- 1 110 2 220 // we could also replace list of col names with a function colSel: col => col.name == "b" or col.name == "c" g.foldCols(colSel, "bc", sum)