3 Replies Latest reply on Sep 27, 2016 3:12 AM by Hardi Saputra

    Return specific cluster belong to new data set (k-means using R)

    Hardi Saputra

      Hi all,
      I am performing k-means in tableau desktop. I could successfully return the new field consist of number of cluster for each case.
      Now I am modifying the syntax to return an integer (cluster number) which my new input belong to. I just found the way through someone's post but it didnt work.  here is my code:




      num.k= .arg5[1];


      cl = kmeans(data,num.k);


      x = c(.arg7,.arg8,.arg9,.arg10);

      closest.cluster = function(x) {

        cluster.dist <- apply(cl$centers, 1, function(y) sqrt(sum((x-y)^2)))



      SUM([Holiday Type Value]),SUM([NumberOfPersons]),SUM([Season Value]),SUM([Price]),[Number of K],[Seed],[Filter Holiday Type],[Filter Number of Persons],[Filter Season],[Filter Price])


      where did i do wrong? thanks in advance