restoring useful DoubleArray utils not in TableConverter
package tech.tablesaw.util;
+import com.google.common.base.Preconditions;
import tech.tablesaw.api.NumberColumn;
+import tech.tablesaw.columns.Column;
import tech.tablesaw.table.TableSlice;
import tech.tablesaw.table.TableSliceGroup;
+import java.util.List;
+
/**
* Utility functions for creating 2D double arrays from columns and other arrays
*/
@@ -34,6 +38,23 @@ public class DoubleArrays {
return result;
}
+ public static double[][] to2dArray(Column... columns) {
+ Preconditions.checkArgument(columns.length >= 1);
+ int obs = columns[0].size();
+ double[][] allVals = new double[obs][columns.length];
+
+ for (int r = 0; r < obs; r++) {
+ for (int c = 0; c < columns.length; c++) {
+ allVals[r][c] = columns[c].getDouble(r);
+ }
+ }
+ return allVals;
+ }
+
+ public static double[][] to2dArray(List<Column> columnList) {
+ return to2dArray(columnList.toArray(new Column[columnList.size()]));
+ }
+
public static double[][] to2dArray(TableSliceGroup views, int columnNumber) {
int viewCount = views.size();
@@ -50,4 +71,21 @@ public class DoubleArrays {
return allVals;
}
+ public static double[][] to2dArray(double[] x, double[] y) {
+ double[][] allVals = new double[x.length][2];
+ for (int i = 0; i < x.length; i++) {
+ allVals[i][0] = x[i];
+ allVals[i][1] = y[i];
+ }
+ return allVals;
+ }
+
+ public static double[][] to2dArray(Column x, Column y) {
+ double[][] allVals = new double[x.size()][2];
+ for (int i = 0; i < x.size(); i++) {
+ allVals[i][0] = x.getDouble(i);
+ allVals[i][1] = y.getDouble(i);
+ }
+ return allVals;
+ }
}
