use of tech.tablesaw.api.DoubleColumn in project symja_android_library by axkr.
the class CrossTab method percents.
public static Table percents(Table table, String column1) {
Table countTable = counts(table, column1);
Table percentTable = Table.create(countTable.name());
percentTable.addColumns(countTable.column(0).copy());
IntColumn countsColumn = countTable.intColumn("Count");
DoubleColumn pctsColumn = DoubleColumn.create("Percents");
double sum = countsColumn.sum();
for (int i = 0; i < countsColumn.size(); i++) {
pctsColumn.append(countsColumn.getDouble(i) / sum);
}
percentTable.addColumns(pctsColumn);
return percentTable;
}
use of tech.tablesaw.api.DoubleColumn 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.DoubleColumn 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.DoubleColumn in project symja_android_library by axkr.
the class NumberInterpolator method linear.
/**
* Linearly interpolates missing values.
*/
public DoubleColumn linear() {
DoubleColumn result = col.asDoubleColumn();
int last = -1;
for (int i = 0; i < col.size(); i++) {
if (!col.isMissing(i)) {
if (last >= 0 && last != i - 1) {
for (int j = last + 1; j < i; j++) {
result.set(j, col.getDouble(last) + (col.getDouble(i) - col.getDouble(last)) * (j - last) / (i - last));
}
}
last = i;
}
}
return result;
}
use of tech.tablesaw.api.DoubleColumn in project symja_android_library by axkr.
the class NumberMapFunctions method difference.
default DoubleColumn difference() {
DoubleColumn returnValue = DoubleColumn.create(this.name(), this.size());
if (isEmpty()) {
return returnValue;
}
returnValue.setMissing(0);
for (int current = 1; current < size(); current++) {
returnValue.set(current, subtract(getDouble(current), getDouble(current - 1)));
}
return returnValue;
}
Aggregations