[英]Error in R: NA/NaN/Inf in foreign function call using hclust()
I'm trying to cluster MLB data by starting pitcher's name.我试图通过开始投手的名字来聚集 MLB 数据。 I've combed through the data I'm using and there is nothing with a value of na and I omitted them in the code below.
我梳理了我正在使用的数据,没有任何值为 na 的数据,我在下面的代码中省略了它们。 Clustdata looks completely good to me ClustData preview but I get this error:
Clustdata 对我来说看起来非常好ClustData 预览,但我收到此错误:
NAs introduced by coercionError in hclust(d, method = "single", members = clustdata[, 1]): NA/NaN/Inf in foreign function call (arg 7)由 hclust(d, method = "single", members = clustdata[, 1]) 中的 coercionError 引入的 NA:外国 function 调用中的 NA/NaN/Inf (arg 7)
I want to cluster that table by pitcher name by those attributes Anyone have any ideas?我想通过这些属性按投手名称对该表进行聚类有人有什么想法吗? Thanks!
谢谢! I'm new to R
我是 R 的新手
data7 = read.csv("GL2007.csv", header = T)
data8 = data.frame(na.omit(data7[c(10,23,24,25,26,30,31,33,105)]))
scoreagg = aggregate(v_score ~ h_starting_pitcher_name, data8, mean)
hitsagg = aggregate(v_hits ~ h_starting_pitcher_name, data8, mean)
doubagg = aggregate(v_doubles~ h_starting_pitcher_name, data8, mean)
tripagg = aggregate(v_triples~ h_starting_pitcher_name, data8, mean)
hragg = aggregate(v_homeruns ~ h_starting_pitcher_name, data8, mean)
hbpagg = aggregate(v_hit_by_pitch ~ h_starting_pitcher_name, data8, mean)
walksagg = aggregate(v_walks~ h_starting_pitcher_name, data8, mean)
SOagg = aggregate(v_strikeouts~ h_starting_pitcher_name, data8, mean)
clustdata = data.frame(scoreagg$h_starting_pitcher_name, scoreagg$v_score,hitsagg$v_hits,doubagg$v_doubles,tripagg$v_triples,hragg$v_homeruns,hbpagg$v_hit_by_pitch,walksagg$v_walks,SOagg$v_strikeouts)
library(NbClust)
d = dist(as.matrix(clustdata[,2:9]), method = "euclidean")
hc_1 = hclust(d, method = "single", members = clustdata[,1])
Since not a lot of details given in the question, it seems you are not using the members
argument correctly.由于问题中没有提供很多细节,因此您似乎没有正确使用
members
参数。
Just leave it as NULL if your aim is only to obtain a clustering.如果您的目标只是获得聚类,请将其保留为 NULL。
hc_1 = hclust(d, method = "single")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.