Error in using HCLUST

#1

HI - I'm getting an error while running the HCLUST code below ... ALso - My distance matrix is big ... (Attached for reference)

Calculations ;

csim <- csim %*% t(csim)
cdist <- as.dist(1 - csim)
hc <- hclust(cdist, "ward.D")

Error : Error in hclust(cdist, "ward.D") : NA/NaN/Inf in foreign function call (arg 11)

Please suggest.

Thanks,
Parvati Patnaik

0 Likes

#2

Welcome to the community, Parvati!

You forgot to attach the distance matrix. So, I can only guess that some elements of it are missing or infinite. Can you please check that? Try with sum(is.infinite(x = cdist)), sum(is.na(x = cdist)) and sum(is.nan(x = cdist)).

If that doesn't solve your problem, can you please provide a REPRoducible EXample of your problem? It provides more specifics of your problem, and it helps others to understand what problem you are facing.

In case you don't know how to make a reprex, here's a great link:

Also, please share a small part of the dataset in a copy-paste friendly format.

The dput function is very handy, if you have stored the dataset in some R object.

In case you've your dataset on a spreadsheet, check out the datapasta package. Take a look at the following link:

0 Likes