I am beginner in R. I have graph with 11 vertices. I am trying to make dendrogram with single linkage, but I am getting some strange error. This is my own distance matrix which I created manually. Its matrix 11x11.
mat<-matrix(c(0,1,2,3,3,1,2,2,2,3,2,
1,0,1,2,2,2,1,2,3,2,3,
2,1,0,1,1,2,2,1,2,3,3,
3,2,1,0,1,3,3,2,3,4,4,
3,2,1,1,0,3,3,2,3,4,4,
1,2,2,3,3,0,1,1,1,2,1,
2,1,2,3,3,1,0,1,2,1,2,
2,2,1,2,2,1,1,0,1,2,2,
2,3,2,3,3,1,2,1,0,1,1,
3,2,3,4,4,2,1,2,1,0,1,
2,3,3,4,4,1,2,2,1,1,0),nrow=11,byrow=TRUE)
rownames(mat)<-c('v1', 'v2', 'v3', 'v4', 'v5', 'v6', 'v7', 'v8', 'v9', 'v10', 'v11')
colnames(mat)<-c('v1', 'v2', 'v3', 'v4', 'v5', 'v6', 'v7', 'v8', 'v9', 'v10', 'v11')
When I try launch my hclust function by this:
singleLinkage <- hclust(mat,method="single")
I get error Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : missing value where TRUE/FALSE needed. I think error is in the matrix. In hclust function should be some matrix which is created by dist function, but I did not understand that concept at all. Please can anyone help where is the mistake? Thank you very much. :)
You guessed it. You need to pass hclust
a dist
object. You get that by calculating dist, or, as in your case, coercing the matrix to dist (since it already has its properties).
hclust(as.dist(mat), method = "single")