use of tech.tablesaw.api.DoubleColumn in project symja_android_library by axkr.
the class NumberMapFunctions method cumProd.
/**
* Returns a new column with a cumulative product calculated
*/
default DoubleColumn cumProd() {
double total = 1.0;
DoubleColumn newColumn = DoubleColumn.create(name() + "[cumProd]", size());
for (int i = 0; i < size(); i++) {
double value = getDouble(i);
if (!DoubleColumnType.valueIsMissing(value)) {
total *= value;
}
newColumn.set(i, total);
}
return newColumn;
}
use of tech.tablesaw.api.DoubleColumn in project symja_android_library by axkr.
the class NumberMapFunctions method asPercent.
/**
* Return the elements of this column as the percentages of their value relative to the sum of all
* elements
*/
default DoubleColumn asPercent() {
DoubleColumn pctColumn = DoubleColumn.create(name() + " percents", size());
double total = sum();
for (int i = 0; i < size(); i++) {
if (total != 0) {
pctColumn.set(i, (getDouble(i) / total) * 100);
}
}
return pctColumn;
}
use of tech.tablesaw.api.DoubleColumn in project symja_android_library by axkr.
the class NumberMapFunctions method cumMax.
/**
* Returns a new column with a cumulative maximum calculated
*/
default DoubleColumn cumMax() {
double max = DoubleColumnType.missingValueIndicator();
DoubleColumn newColumn = DoubleColumn.create(name() + "[cumMax]", size());
for (int i = 0; i < size(); i++) {
double value = getDouble(i);
if (!DoubleColumnType.valueIsMissing(value)) {
max = DoubleColumnType.valueIsMissing(max) ? value : Math.max(max, value);
}
newColumn.set(i, max);
}
return newColumn;
}
use of tech.tablesaw.api.DoubleColumn in project symja_android_library by axkr.
the class NumberMapFunctions method pctChange.
/**
* Returns a new column with a percent change calculated
*/
default DoubleColumn pctChange() {
DoubleColumn newColumn = DoubleColumn.create(name() + "[pctChange]", size());
newColumn.setMissing(0);
for (int i = 1; i < size(); i++) {
newColumn.set(i, divide(getDouble(i), getDouble(i - 1)) - 1);
}
return newColumn;
}
use of tech.tablesaw.api.DoubleColumn in project symja_android_library by axkr.
the class NumberMapFunctions method subtract.
default DoubleColumn subtract(NumericColumn<?> column2) {
int col1Size = size();
int col2Size = column2.size();
if (col1Size != col2Size)
throw new IllegalArgumentException("The columns must have the same number of elements");
DoubleColumn result = DoubleColumn.create(name() + " - " + column2.name(), col1Size);
for (int r = 0; r < col1Size; r++) {
result.set(r, subtract(getDouble(r), column2.getDouble(r)));
}
return result;
}
Aggregations