- struct tab_table *t;
- int nc, nr, currow;
- int i, j;
- nc = qc->ngroups + 1;
- nr = qc->n_vars + 4;
- t = tab_create (nc, nr);
- tab_headers (t, 0, nc - 1, 0, 1);
- currow = 0;
- if (!initial)
- {
- tab_title (t, _("Final Cluster Centers"));
- }
- else
- {
- tab_title (t, _("Initial Cluster Centers"));
- }
- tab_box (t, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, nc - 1, nr - 1);
- tab_joint_text (t, 1, 0, nc - 1, 0, TAB_CENTER, _("Cluster"));
- tab_hline (t, TAL_1, 1, nc - 1, 2);
- currow += 2;
-
- for (i = 0; i < qc->ngroups; i++)
- {
- tab_text_format (t, (i + 1), currow, TAB_CENTER, "%d", (i + 1));
- }
- currow++;
- tab_hline (t, TAL_1, 1, nc - 1, currow);
- currow++;
- for (i = 0; i < qc->n_vars; i++)
- {
- tab_text (t, 0, currow + i, TAB_LEFT,
- var_to_string (qc->vars[i]));
+ struct pivot_table *table = pivot_table_create (
+ initial ? N_("Initial Cluster Centers") : N_("Final Cluster Centers"));
+
+ struct pivot_dimension *clusters = pivot_dimension_create (
+ table, PIVOT_AXIS_COLUMN, N_("Cluster"));
+ clusters->root->show_label = true;
+ for (size_t i = 0; i < qc->ngroups; i++)
+ pivot_category_create_leaf (clusters->root,
+ pivot_value_new_integer (i + 1));
+
+ struct pivot_dimension *variables = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Variable"));
+ for (size_t i = 0; i < qc->n_vars; i++)
+ pivot_category_create_leaf (variables->root,
+ pivot_value_new_variable (qc->vars[i]));
+
+ const gsl_matrix *matrix = (initial
+ ? kmeans->initial_centers
+ : kmeans->centers);
+ for (size_t i = 0; i < qc->ngroups; i++)
+ for (size_t j = 0; j < qc->n_vars; j++)
+ {
+ double x = gsl_matrix_get (matrix, kmeans->group_order->data[i], j);
+ union value v = { .f = x };
+ pivot_table_put2 (table, i, j,
+ pivot_value_new_var_value (qc->vars[j], &v));