als-statistics
Version:
Modular JS statistics toolkit for Node.js and the browser: descriptive stats, correlations (Pearson/Spearman/Kendall), t-tests & ANOVA (Student/Welch), reliability (Cronbach’s alpha), regression (linear/logistic), clustering (DBSCAN/HDBSCAN), and table/co
14 lines (13 loc) • 508 B
JavaScript
export function transpose({ colValues, n, k }, rowKeys = [], colKeys = []) {
const withRowKeys = rowKeys.length === n;
const withColKeys = colKeys.length === k;
const obj = withRowKeys ? {} : new Array(n);
for (let i = 0; i < n; i++) {
const arr = withColKeys ? {} : new Array(k);
for (let j = 0; j < k; j++) {
arr[withColKeys ? (colKeys[j] ?? j) : j] = colValues[j].values[i];
}
obj[withRowKeys ? (rowKeys[i] ?? i) : i] = arr;
}
return obj;
}