factoextra
factoextra copied to clipboard
Problem with fviz_nbclust()
I'm doing a report for a data analysis and statistical learning subject. The problem is in the clustering phase. I have to find the optimal number of clusters, and i already done. But when i try to display the graph with the following function it gives me an error:
nb<-NbClust(df, diss=NULL,distance="euclidean",method="average")
fviz_nbclust(nb) Error in if (class(best_nc) == "numeric") print(best_nc) else if (class(best_nc) == : the condition has length > 1
df is the standardized data set with only numerical data. The error is referred to the fviz_nbclust function. I'd like to know what to do. I have already try to reinstall the packages, RStudio, everything but nothing. I also did, inside the NbClust() function the min_nc or max_nc and stuff like that.
Thanks for your help.
Exactly the same...
Thanks for your help
Same here too. Class(best_nc) from NbClust object return a list("matrix","array") of length of 2. The conditions (class(best_nc) == "numeric") and (class(best_nc)== "matrix") can be changed into (class(best_nc)[1] == "numeric") and (class(best_nc)[1] == "matrix") , in the fviz_nbclust function, . The graph output does not have the number of cluster sorted. One can add as.numeric in df <- data.frame(Number_clusters = as.numeric(names(ss)), freq = ss, stringsAsFactors = TRUE ) to sort them, in the .viz_NbClust function.
See here for fix posted on StackOverflow -
https://stackoverflow.com/questions/72075707/rstudio-error-with-the-fviz-nbclust-function