use of tech.tablesaw.api.StringColumn 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.StringColumn 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.StringColumn in project symja_android_library by axkr.
the class DateMapFunctions method yearWeek.
/**
* Returns a StringColumn with the year and week-of-year derived from this column concatenated
* into a String that will sort lexicographically in temporal order.
*
* <p>This simplifies the production of plots and tables that aggregate values into standard
* temporal units (e.g., you want monthly data but your source data is more than a year long and
* you don't want months from different years aggregated together).
*/
default StringColumn yearWeek() {
StringColumn newColumn = StringColumn.create(this.name() + " year & week");
for (int r = 0; r < this.size(); r++) {
int c1 = this.getIntInternal(r);
if (DateColumn.valueIsMissing(c1)) {
newColumn.appendMissing();
} else {
String ym = String.valueOf(PackedLocalDate.getYear(c1));
ym = ym + "-" + Strings.padStart(String.valueOf(PackedLocalDate.getWeekOfYear(c1)), 2, '0');
newColumn.append(ym);
}
}
return newColumn;
}
use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class DateMapFunctions method yearDay.
/**
* Returns a StringColumn with the year and day-of-year derived from this column concatenated into
* a String that will sort lexicographically in temporal order.
*
* <p>This simplifies the production of plots and tables that aggregate values into standard
* temporal units (e.g., you want monthly data but your source data is more than a year long and
* you don't want months from different years aggregated together).
*/
default StringColumn yearDay() {
StringColumn newColumn = StringColumn.create(this.name() + " year & month");
for (int r = 0; r < this.size(); r++) {
int c1 = this.getIntInternal(r);
if (DateColumn.valueIsMissing(c1)) {
newColumn.appendMissing();
} else {
String ym = String.valueOf(PackedLocalDate.getYear(c1));
ym = ym + "-" + Strings.padStart(String.valueOf(PackedLocalDate.getDayOfYear(c1)), 3, '0');
newColumn.append(ym);
}
}
return newColumn;
}
use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class DateTimeMapFunctions method yearMonth.
/**
* Returns a StringColumn with the year and month from this column concatenated into a String that
* will sort lexicographically in temporal order.
*
* <p>This simplifies the production of plots and tables that aggregate values into standard
* temporal units (e.g., you want monthly data but your source data is more than a year long and
* you don't want months from different years aggregated together).
*/
default StringColumn yearMonth() {
StringColumn newColumn = StringColumn.create(this.name() + " year & month");
for (int r = 0; r < this.size(); r++) {
long c1 = this.getLongInternal(r);
if (DateTimeColumn.valueIsMissing(c1)) {
newColumn.append(StringColumnType.missingValueIndicator());
} else {
String ym = String.valueOf(getYear(c1));
ym = ym + "-" + Strings.padStart(String.valueOf(getMonthValue(c1)), 2, '0');
newColumn.append(ym);
}
}
return newColumn;
}
Aggregations