10 Replies Latest reply on Sep 18, 2018 2:55 AM by Daniel Hernandez

    K-Means Cluster with R

    Vince Ho

      I was given a set of code to run the k-means function with R in a calculated field.

       

      My R connection is fine and I had previously ran linear regression this way.

       

      But with this k-means function I kept getting an error message:

      Error in base::parse(text = .cmd) : <text>:1:62: unexpected symbol

      1: result <- kmeans(x = data.frame(.arg1,.arg2,.arg3,.arg4), 3) result

                                                                       ^

      I was using the classic Fisher's Iris flower petal data set to test this with.

      Here is the code used in the calculated field named "Clusters":

      SCRIPT_INT('result <- kmeans(x = data.frame(.arg1,.arg2,.arg3,.arg4), 3) result$cluster',

      SUM([Sepal length]),SUM([Sepal width]),SUM([Petal length]),SUM([Petal width]))

       

      Attached is the .twbx file.

       

      Can someone help me figure out what I am doing wrong?

       

      Thanks much!