use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class CrossTab method tablePercents.
private static Table tablePercents(Table xTabCounts) {
Table pctTable = Table.create("Crosstab Table Proportions: ");
StringColumn labels = StringColumn.create(LABEL_COLUMN_NAME);
pctTable.addColumns(labels);
double grandTotal = xTabCounts.numberColumn(xTabCounts.columnCount() - 1).getDouble(xTabCounts.rowCount() - 1);
for (int i = 0; i < xTabCounts.rowCount(); i++) {
labels.append(xTabCounts.column(0).getString(i));
}
// create the new cols
DoubleColumn[] newColumns = new DoubleColumn[xTabCounts.columnCount() - 1];
for (int i = 1; i < xTabCounts.columnCount(); i++) {
Column<?> column = xTabCounts.column(i);
newColumns[i - 1] = DoubleColumn.create(column.name());
}
for (int i = 0; i < xTabCounts.rowCount(); i++) {
for (int c = 0; c < newColumns.length; c++) {
if (grandTotal == 0) {
newColumns[c].append(Double.NaN);
} else {
newColumns[c].append(xTabCounts.numberColumn(c + 1).getDouble(i) / grandTotal);
}
}
}
pctTable.addColumns(newColumns);
return pctTable;
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class CrossTab method columnPercents.
private static Table columnPercents(Table xTabCounts) {
Table pctTable = Table.create("Crosstab Column Proportions: ");
StringColumn labels = StringColumn.create(LABEL_COLUMN_NAME);
pctTable.addColumns(labels);
// setup the labels
for (int i = 0; i < xTabCounts.rowCount(); i++) {
labels.append(xTabCounts.column(0).getString(i));
}
// create the new cols
DoubleColumn[] newColumns = new DoubleColumn[xTabCounts.columnCount() - 1];
for (int i = 1; i < xTabCounts.columnCount(); i++) {
Column<?> column = xTabCounts.column(i);
newColumns[i - 1] = DoubleColumn.create(column.name());
}
// get the column totals
double[] columnTotals = new double[newColumns.length];
int totalRow = xTabCounts.rowCount() - 1;
for (int i = 1; i < xTabCounts.columnCount(); i++) {
columnTotals[i - 1] = xTabCounts.numberColumn(i).getDouble(totalRow);
}
// calculate the column pcts and update the new table
for (int i = 0; i < xTabCounts.rowCount(); i++) {
for (int c = 0; c < newColumns.length; c++) {
if (columnTotals[c] == 0) {
newColumns[c].append(Double.NaN);
} else {
newColumns[c].append(xTabCounts.numberColumn(c + 1).getDouble(i) / columnTotals[c]);
}
}
}
pctTable.addColumns(newColumns);
return pctTable;
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class ByteDictionaryMap method countByCategory.
/**
*/
@Override
public Table countByCategory(String columnName) {
Table t = Table.create("Column: " + columnName);
StringColumn categories = StringColumn.create("Category");
IntColumn counts = IntColumn.create("Count");
// Now uses the keyToCount map
for (Map.Entry<Byte, Integer> entry : keyToCount.byte2IntEntrySet()) {
categories.append(getValueForKey(entry.getKey()));
counts.append(entry.getValue());
}
t.addColumns(categories);
t.addColumns(counts);
return t;
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class IntDictionaryMap method countByCategory.
/**
*/
@Override
public Table countByCategory(String columnName) {
Table t = Table.create("Column: " + columnName);
StringColumn categories = StringColumn.create("Category");
IntColumn counts = IntColumn.create("Count");
// Now uses the keyToCount map
for (Map.Entry<Integer, Integer> entry : keyToCount.int2IntEntrySet()) {
categories.append(getValueForKey(entry.getKey()));
counts.append(entry.getValue());
}
t.addColumns(categories);
t.addColumns(counts);
return t;
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class Stats method asTable.
public Table asTable() {
Table t = Table.create(name);
StringColumn measure = StringColumn.create("Measure");
DoubleColumn value = DoubleColumn.create("Value");
t.addColumns(measure);
t.addColumns(value);
measure.append("Count");
value.append(n);
measure.append("sum");
value.append(sum());
measure.append("Mean");
value.append(mean());
measure.append("Min");
value.append(min());
measure.append("Max");
value.append(max());
measure.append("Range");
value.append(range());
measure.append("Variance");
value.append(variance());
measure.append("Std. Dev");
value.append(standardDeviation());
return t;
}
Aggregations