{"action":"created","issue":{"url":"https://api.github.com/repos/talgalili/dendextend/issues/5","labels_url":"https://api.github.com/repos/talgalili/dendextend/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/talgalili/dendextend/issues/5/comments","events_url":"https://api.github.com/repos/talgalili/dendextend/issues/5/events","html_url":"https://github.com/talgalili/dendextend/issues/5","id":55046321,"number":5,"title":"cutree returns all zero vector","user":{"login":"grafab","id":5277911,"avatar_url":"https://avatars.githubusercontent.com/u/5277911?v=3","gravatar_id":"","url":"https://api.github.com/users/grafab","html_url":"https://github.com/grafab","followers_url":"https://api.github.com/users/grafab/followers","following_url":"https://api.github.com/users/grafab/following{/other_user}","gists_url":"https://api.github.com/users/grafab/gists{/gist_id}","starred_url":"https://api.github.com/users/grafab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grafab/subscriptions","organizations_url":"https://api.github.com/users/grafab/orgs","repos_url":"https://api.github.com/users/grafab/repos","events_url":"https://api.github.com/users/grafab/events{/privacy}","received_events_url":"https://api.github.com/users/grafab/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-21T17:00:59Z","updated_at":"2015-01-22T08:15:01Z","closed_at":"2015-01-22T08:15:01Z","body":"I ran into problems with cutree, when I had a tree with zero distance leafs.\r\nHere is a minimal example that reproduces the problem:\r\n> dend<-as.dendrogram(hclust(dist(c(1,1,1,2,2))))\r\n> cutree(dend,k=5)\r\n> [1] 0 0 0 0 0\r\n\r\nI expected the result to be:\r\n> cutree(hclust(dist(c(1,1,1,2,2))),k=5)\r\n> [1] 1 2 3 4 5\r\n\r\nI figured out that it has to do with the function `heights_per_k.dendrogram`.\r\nIt results in negative values for h:\r\n\r\n> heights_per_k.dendrogram(dend)\r\n>    1    2    0 \r\n>  1.5  0.5 -0.5\r\n\r\nNegative height reproduced the results, that I got before:\r\n> cutree(dend,h=-0.5)\r\n> [1] 0 0 0 0 0"},"comment":{"url":"https://api.github.com/repos/talgalili/dendextend/issues/comments/70985257","html_url":"https://github.com/talgalili/dendextend/issues/5#issuecomment-70985257","issue_url":"https://api.github.com/repos/talgalili/dendextend/issues/5","id":70985257,"user":{"login":"grafab","id":5277911,"avatar_url":"https://avatars.githubusercontent.com/u/5277911?v=3","gravatar_id":"","url":"https://api.github.com/users/grafab","html_url":"https://github.com/grafab","followers_url":"https://api.github.com/users/grafab/followers","following_url":"https://api.github.com/users/grafab/following{/other_user}","gists_url":"https://api.github.com/users/grafab/gists{/gist_id}","starred_url":"https://api.github.com/users/grafab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grafab/subscriptions","organizations_url":"https://api.github.com/users/grafab/orgs","repos_url":"https://api.github.com/users/grafab/repos","events_url":"https://api.github.com/users/grafab/events{/privacy}","received_events_url":"https://api.github.com/users/grafab/received_events","type":"User","site_admin":false},"created_at":"2015-01-22T08:15:01Z","updated_at":"2015-01-22T08:15:01Z","body":"I think you have three options here:\r\n1. Give an error, like for k=6.\r\n2. Return the result of the highest possible k. In the example k=2.\r\n3. Split up one of the groups as it happens for hclust objects:\r\n\r\n> cutree(hclust(dist(c(1,1,1,2,2))),k=3)\r\n> [1] 1 1 1 2 3\r\n\r\nThe last one would be consistent with stats:cutree. However, I would appreciate a warning, because the result differs, if the orientation of the input changes:\r\n> cutree(hclust(dist(c(2,2,1,1,1))),k=3)\r\n> [1] 1 1 2 2 3\r\n"}}