[R] K-Means Clustering

Jordan van Rijn vanrijn9 at fastmail.fm
Fri May 9 09:12:55 CEST 2008


Hello,

I am hoping you can help me with a question concerning kmeans clustering
in R. I am working with the following data-set (abbreviated):


        BMW Ford Infiniti Jeep Lexus Chrysler Mercedes Saab Porsche
        Volvo
  [1,]   6    8        2    8     4        5        4    4       7     7
  [2,]   8    7        4    6     4        1        6    7       8     5
  [3,]   8    2        4    6     3        2        7    4       4     4
  [4,]   7    4        4    6     6        1        6    3       5     5
  [5,]   6    2        4    5     5        1        3    3       6     3
  [6,]   6    7        3    6     5        1        8    4       8     2
  [7,]   1    6        6    7     5        2        6    6       5     6
  [8,]   3    6        6    4     5        1        4    2       1     1
  [9,]   6    7        5    8     4        1        6    6       8     5
 [10,]   6    7        5    9     3        1        2    5       1     8

When I try to scale my data and perform kmeans clustering, I get the
following errors:
 new <- scale(new)
Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric
> cl <- kmeans(new, 4)
Error in switch(nmeth, { : NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message:
In switch(nmeth, { : NAs introduced by coercion

This is confusing to me since all of the data is numeric and there are
no missing values. Is there something I need to do to my data to prepare
it for kmeans? I have tried many matrix transformations but nothing has
worked so far.

Your help is much appreciated.

Thanks,
  jordan

-- 
  Jordan van Rijn
  vanrijn9 at fastmail.fm



More information about the R-help mailing list