如何访问R中树形图的属性 [英] How to access attributes of a dendrogram in R
本文介绍了如何访问R中树形图的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我与创建一个树状图
From a dendrogram which i created with
hc<-hclust(kk)
hcd<-as.dendrogram(hc)
我挑了个支行
k=hcd[[2]][[2]][[2]][[2]][[2]][[2]][[2]][1]
当我只是有显示K,这给:
When i simply have k displayed, this gives:
> k
[[1]]
[[1]][[1]]
[1] 243
attr(,"label")
[1] "NAfrica_002"
attr(,"members")
[1] 1
attr(,"height")
[1] 0
attr(,"leaf")
[1] TRUE
[[1]][[2]]
[1] 257
attr(,"label")
[1] "NAfrica_016"
attr(,"members")
[1] 1
attr(,"height")
[1] 0
attr(,"leaf")
[1] TRUE
attr(,"members")
[1] 2
attr(,"midpoint")
[1] 0.5
attr(,"height")
[1] 37
我
如何访问,例如,中点属性,或者标签的第二个属性?
How can i access, for example, the "midpoint" attribute, or the second of the "label" attributes?
(我希望我在这里使用正确的术语)
(I hope i use the correct terminology here)
我曾尝试之类的东西。
k$midpoint
attr(k,"midpoint")
但都返回'NULL'。
but both returned 'NULL'.
对不起,问题编号为2:我怎么可以在属性之后添加一个标签属性中点
Sorry for question number 2: how could i add a "label" attribute after the attribute "midpoint"?
推荐答案
您 K
仍埋一层太深了。该属性已经设置列表 K
的第一个元素。
Your k
is still buried one layer too deep. The attributes have been set on the first element of the list k
.
attributes(k[[1]]) # Display attributes
attributes(k[[1]])$label # Access attributes
attributes(k[[1]])$label <- 'new' # Change attribute
另外,你可以使用 ATTR
:
attr(k[[1]],'label') # Display attribute
这篇关于如何访问R中树形图的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文