Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)相关的知识,希望对你有一定的参考价值。

Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)

目录

Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)

#仿真数据

#问题

#解决

#完整错误:


#仿真数据

#create data frame
df <- data.frame(var1=c(2, 4, 4, 6, 7, 8, 8, 9, 9, 12),
                 var2=c(12, 14, 14, 8, 8, 15, 16, 9, 9, 11),
                 var3=c(22, NA, 23, 24, 28, 23, 19, 16, 12, 15))

row.names(df) <- LETTERS[1:10]

#view data frame
df

#问题

#attempt to perform k-means clustering with k = 3 clusters
km <- kmeans(df, centers = 3)

#解决

#删除缺失值所在的数据行在重新进行聚类分析

#remove rows with NA values
df <- na.omit(df)

#perform k-means clustering with k = 3 clusters
km <- kmeans(df, centers = 3)

#view results
km

#完整错误:

> #create data frame
> df <- data.frame(var1=c(2, 4, 4, 6, 7, 8, 8, 9, 9, 12),
+                  var2=c(12, 14, 14, 8, 8, 15, 16, 9, 9, 11),
+                  var3=c(22, NA, 23, 24, 28, 23, 19, 16, 12, 15))

> row.names(df) <- LETTERS[1:10]

> #view data frame
> df
  var1 var2 var3
A    2   12   22
B    4   14   NA
C    4   14   23
D    6    8   24
E    7    8   28
F    8   15   23
G    8   16   19
H    9    9   16
I    9    9   12
J   12   11   15
> #attempt to perform k-means clustering with k = 3 clusters
> km <- kmeans(df, centers = 3)
Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)

以上是关于Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)的主要内容,如果未能解决你的问题,请参考以下文章

BOWTIE2 进行基因组比对

[RxJS] Error Handling in RxJS

# Error in colSums(iris) : ‘x‘ must be numeric,# Error in rowSums(iris) : ‘x‘ must be numeric

1064 - syntax error, error in :'Id`) USING BTREE

ERROR 1064 (42000): You have an error in your SQL syntax...

Error in eval(family$initialize) : y值必需满足0 <= y <= 1Error in eval(family$initialize) : y values mus