R:缺少需要TRUE / FALSE的值

时间:2017-05-01 06:42:49

标签: r

我正在尝试在绘制dandrogram之前为列指定字母。这是代码>

data<-data.frame(X=c(1,2,3,4),Y=c(1,3,2,1))
dataset1<-as.data.frame(as.matrix( dist(data)))
colnames(dataset1) <- c("A","B","C","D")
rownames(dataset1) <- c("A","B","C","D")
plot(hclust(dataset1, method = "single"))

但在最后一行,它抱怨&gt;

Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : 
  missing value where TRUE/FALSE needed

1 个答案:

答案 0 :(得分:0)

距离矩阵仅包含3行和3列。更容易将标签放在data.frame的row.names中并绘制树形图。

df <- data.frame(X=c(1,2,3,4),Y=c(1,3,2,1), row.names=c("A","B","C","D"))
plot(hclust(dist(df)))

enter image description here