I was teaching a class today and ran into an error when trying to visualize the results of the NbClust() function.
Here's my code and resulting error. I'm using R version 4.3.1, factoextra version 1.0.7, NbClust version 3.0.1, and the R dataset "USArrests".
I saw a post on another site that indicates that there is a problem with the resulting data in Best.nc, but I haven't been able to determine a solution for this yet. Any ideas?
#> load data
data("USArrests")
View(USArrests)
#> scale
data <- scale(USArrests)
View(data)
#> choose optimal value for k with NbClust()
library(NbClust)
nb <- NbClust(data,
distance = 'euclidean',
method = 'kmeans',
min.nc = 2,
max.nc = 15,
index = "all"
)
#> visualize
library(factoextra)
fviz_nbclust(nb)
#>Error in if (class(best_nc) == "numeric") print(best_nc) else if (class(best_nc) == :
#> the condition has length > 1