fixes: TODO, debug test.clustering.R and finish writing clustering.R
[epclust.git] / epclust / tests / testthat / helper.computeMedoidsIndices.R
diff --git a/epclust/tests/testthat/helper.computeMedoidsIndices.R b/epclust/tests/testthat/helper.computeMedoidsIndices.R
new file mode 100644 (file)
index 0000000..9342feb
--- /dev/null
@@ -0,0 +1,10 @@
+#R-equivalent of computeMedoidsIndices, requiring a matrix
+#(thus potentially breaking "fit-in-memory" hope)
+R_computeMedoidsIndices <- function(medoids, series)
+{
+       nb_series = ncol(series)
+       mi = rep(NA,nb_series)
+       for (i in 1:nb_series)
+               mi[i] <- which.min( colSums( sweep(medoids, 1, series[,i], '-')^2 ) )
+       mi
+}