R kmeans NAs with an external function error (arg 13)

I have numeric data in a vector and I'm trying to run kmeans. Below is the error

> kmeans( mydata, centers = 2 ) # trying centers 2 to 20 but failing at 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.

+4
source share
3 answers

Try using a previous version of R, for example 2.15.3. It worked for me.

, , , v3.1.2, NA.

: kmeans 46 NA

+2

, () R 3.0.1, . http://bugs.r-project.org/bugzilla/show_bug.cgi?id=15364#c6 Gökcen Eraslan .

​​10 R 3.2.0 alpha ( R 3.2.0 ). , , nrow(x) <= 50 32- (2 ^ 31 - 1), kmeans() R, Fortran, .

+2

I have the same error, and when I read the error log, it says NaN, which means no number. So I double check my dataset and yes, there is a line containing a string (words). I delete this line and it works fine.

+1
source

Source: https://habr.com/ru/post/1531701/


All Articles