Stuck with an error implementing kmeans in r

I am trying to implement kmeans clustering algorithm using Manhattan distance. I used the following code for implementing the same:

data<- read.csv("garments_worker_productivity.csv")
cluster<-kmeans(data,3,iter.max=10, nstart=1, method = "Manhattan")

I am receiving the following error:

Error in kmeans(data, 3, iter.max = 10, nstart = 1, method = "manhattan") : 
  unused argument (method = "Manhattan")

so how do I implement kmeans using Manhattan and Minkowski distance in r without an error?

thank you!

The kmeans function in the stats package has an argument named algorithm. None of the values it can have is "manhattan".

kmeans(x, centers, iter.max = 10, nstart = 1,
       algorithm = c("Hartigan-Wong", "Lloyd", "Forgy",
                     "MacQueen"), trace=FALSE)

Is that the function you are using?

yes. I realised I was trying this function in amap package

Kmeans(x, centers, iter.max = 10, nstart = 1,
         method = "euclidean")

Is there any other way where I can use Manhattan or Minkowski distance instead of the traditional Euclidean distance in the Kmeans algorithm? Please do let me know how.
Thank you!

Kmeans() accepts the following values of method:

"euclidean", "maximum",
"manhattan", "canberra", "binary", "pearson" , "abspearson" , "abscorrelation",
"correlation", "spearman" or "kendall"

Notice "manhattan" is all lower case.

Still it shows the same error

kmeans is the function from the stats package. Kmeans, with an uppercase K, is the function from amap. Case matters in R.

it says that the function isn't found ;(

Did you run


before trying to use Kmeans()? That assumes you have installed the amap package.

yes I did. amap package is installed

I removed the line


and it worked.. I still don't know why.. thanks though!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.