Skip to content

Is there a bug in kmeans in package mva?

2 messages · Art Salwin, Brian Ripley

#
I created a numeric vector of 49 elements and call kmeans as
follows:
kmeans(x,3)
The second argument, number of centers, is allowed to be a
constant per
the documentation.  However, the call doesn't work and
generates the
following error message:
Error in ncol(x) != ncol(centers) : comparison (2) is
possible only for vector types

Is this a bug or am I doing something wrong?

Looking at the code within kmeans, it appears the statement 
if(ncol(x)!=ncol(centers))
is where it fails, since centers does not get coerced to be
a matrix
and ncol(centers) is NULL.
#
On Tue, 25 Jul 2000, Art Salwin wrote:

            
The help page says

       x: A data frame or matrix of data. 

so that is your error.
right, ncol(x) is NULL.