• Register
1 vote

Problem :

Currently I am learning r. I have the data table "normal" which has the numeric as far as I know normalized values.

If I try to execute the below command

k <- kmeans(normal,center=3)

Then I always face the below error:

“Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)”
I am trying to fix it by researching on it but still unable to fix it.
Can somebody help me in fixing it?
3.2k points

Please log in or register to answer this question.

1 Answer

1 vote

Solution :

I guess your table has lots of NaN/NA/Inf .You can confirm it using the is.na() and is.finite() functions.
You need to remove all the NA/Inf/NaN values from the data. You can take help of "missing value imputation" functions for more details. This one simple method is helpful in replacing NA/Inf/NaN by the row/column mean values. 
The kmeans is unable to handle the data which has NA values.In that case the mean and variance are no longer well defined and also you cant confirm anymore about which center is closest. You can also try to omit the NA values which are present in your table with the use of below code.
km_cluster <- kmeans(na.omit(MyData), 3)

Hope my above solution helped you in fixing your issues.

5.7k points

Related questions

0 votes
1 answer 54 views
Problem: I am stuck now .. need some suggestions .. please help me .. difference between k means and k medoids
asked Apr 21 Ifra 43.4k points
0 votes
1 answer 41 views
Problem: What should I do if I can't find a solution anywhere: Error in the sample.int(m, k) : cannot take a sample larger than the population when 'replace = false'?
asked Jun 10 Nahil 122k points
0 votes
1 answer 313 views
Problem : I have done a lot of research on this extensively without finding any solution on it. I have tried cleaning my data set as follows: library("myraster") impute.mean <- function(l) replace(l, is.na(l) | is.nan(l) | is.infinite(l) , mean(l, na.rm = TRUE)) losses <- ... TRUE, na.rm=TRUE, nan.rm=TRUE) All my research says it should be NA's or Inf's or NaN's in the data but I don't have any
asked Dec 5, 2019 alecxe 7.5k points
0 votes
1 answer 73 views
Problem: I am really new to RStudio and desperately trying to get to grips with it all, so I apologise if this is a silly question. I am trying to generate a heatmap for my RNA Seq Data set using pheatmap, however I am coming up again a number of errors. My data looks like this: ... 2.32 3.45 3.74 ... $ p_value : num 0.00045 0.0006 0.0006 0.00005 Thank you and I look forward to your responses.
asked May 2 Yeamin 23.5k points
0 votes
1 answer 12 views
Problem: Na/nan/inf in foreign function call (arg 6)
asked Jul 13 Sawyer Parviz 166k points
0 votes
1 answer 17 views
Problem: Na/nan/inf in foreign function call (arg 11).
asked Jul 10 Rada Gracelynn 100k points
0 votes
0 answers 14 views
Error in knn(faktor1, joni, target, k = 1, prob = TRUE) : NA/NaN/Inf in foreign function call (arg 6) please help me..
asked Apr 24 robian23 120 points
0 votes
1 answer 61 views
Problem: I'm trying to figure out a solution, need help : More cluster centers than distinct data points.
asked May 24 Florina Gulnar 103k points
0 votes
1 answer 24 views
Problem: I am getting this .. can you help me to solve it? When to use linear vs logistic regression?
asked May 2 Ifra 43.4k points
0 votes
1 answer 20 views
Problem What is an advantage to using the pairwise distance measure in the k-medoid algorithm, instead of the more familiar sum of squared Euclidean distance-type metric to evaluate variance that we find with k-means? Apparently, this different distance metric somehow reduces noise and outliers.
asked Apr 28 alexh 2.6k points