Thanks! I did following your advice .But there is an error.
llibrary(cluster)
mydist <- function(x) as.dist((1-cor(t(x)))/2)
mycluster <- function(x, k) cutree(hclust(mydist(x), method = "average"),k=k)
myclusGap <- clusGap(data.selection03,
FUN = mycluster,
K.max = 10,
B = 100)
Error: $ operator is invalid for atomic vectors
I checked the code of clusGap. Maybe something is wrong with cutree.