I have numeric data in a vector and I'm trying to run kmeans. Below is the error
> kmeans( mydata, centers = 2 )
Error in do_one(nmeth) : NAs in foreign function call (arg 13)
In addition: Warning message:
In do_one(nmeth) : NAs introduced by coercion
> str(mydata)
num [1:44990687] 3.44e-06 3.44e-06 3.44e-06 3.44e-06 4.35e-05 ...
> is.numeric(mydata)
[1] TRUE
My code works for datasets that are smaller than this, so I suspect it might have something to do with the size of the data. Any ideas on how to fix the error? Thanks in advance.
Update: I tried the following:
> x <- length(mydata)
> kmeans( mydata[1:(x/2)], centers = 2 )
> kmeans( mydata[(x/2):x], centers = 2 )
Both calls to kmeans fail without errors. So it looks like this has something to do with the size of the data, not the format / types. If so, what should I do to handle this? Thanks again.
source
share