我尝试通过以下方式将聚类方法构建为函数:
mydata <- mtcars
# Here I construct hclust as a function
hclustfunc <- function(x) hclust(as.matrix(x),method="complete")
# Define distance metric
distfunc <- function(x) as.dist((1-cor(t(x)))/2)
# Obtain distance
d <- distfunc(mydata)
# Call that hclust function
fit<-hclustfunc(d)
# Later I'd do
# plot(fit)
但是为什么会出现以下错误:
Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") :
missing value where TRUE/FALSE needed
正确的方法是什么?