Search in sources :

Example 1 with DoubleColumn

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;
}
Also used : Table(tech.tablesaw.api.Table) TreeBasedTable(com.google.common.collect.TreeBasedTable) DoubleColumn(tech.tablesaw.api.DoubleColumn) IntColumn(tech.tablesaw.api.IntColumn)

Example 2 with DoubleColumn

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;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) TreeBasedTable(com.google.common.collect.TreeBasedTable) DoubleColumn(tech.tablesaw.api.DoubleColumn)

Example 3 with DoubleColumn

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;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) TreeBasedTable(com.google.common.collect.TreeBasedTable) DoubleColumn(tech.tablesaw.api.DoubleColumn)

Example 4 with DoubleColumn

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;
}
Also used : DoubleColumn(tech.tablesaw.api.DoubleColumn)

Example 5 with DoubleColumn

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;
}
Also used : DoubleColumn(tech.tablesaw.api.DoubleColumn)

Aggregations

DoubleColumn (tech.tablesaw.api.DoubleColumn)32 Table (tech.tablesaw.api.Table)7 StringColumn (tech.tablesaw.api.StringColumn)5 TreeBasedTable (com.google.common.collect.TreeBasedTable)4 IntColumn (tech.tablesaw.api.IntColumn)2 LongColumn (tech.tablesaw.api.LongColumn)2 Splitter (com.google.common.base.Splitter)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 LocalDateTime (java.time.LocalDateTime)1 UnsupportedTemporalTypeException (java.time.temporal.UnsupportedTemporalTypeException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CellDateFormatter (org.apache.poi.ss.format.CellDateFormatter)1 CellGeneralFormatter (org.apache.poi.ss.format.CellGeneralFormatter)1 CellNumberFormatter (org.apache.poi.ss.format.CellNumberFormatter)1 CellType (org.apache.poi.ss.usermodel.CellType)1 BooleanColumn (tech.tablesaw.api.BooleanColumn)1 ColumnType (tech.tablesaw.api.ColumnType)1 FloatColumn (tech.tablesaw.api.FloatColumn)1 ShortColumn (tech.tablesaw.api.ShortColumn)1