从Rpy2到R聚类的距离矩阵

时间:2013-04-10 16:21:08

标签: python r numpy cluster-analysis rpy2

我在numpy / scipy中有以下自定义NxN距离矩阵:

dist_matrix =    array([array([5, 4, 2, 3, 2, 3]),
                        array([4, 5, 2, 3, 2, 2]), 
                        array([2, 2, 5, 2, 2, 1]), 
                        array([3, 3, 2, 5, 4, 2]), 
                        array([2, 2, 2, 4, 5, 1]), 
                        array([3, 2, 1, 2, 1, 5])])

如何使用此矩阵在R / ggplot2中进行层次聚类和绘制树状图?如果我尝试通过rpy2将此距离矩阵输入R:

r.hclust(dist_matrix)

我收到错误:

   res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : 
  missing value where TRUE/FALSE needed

1 个答案:

答案 0 :(得分:1)

R函数hclust()正在使用“距离”对象:

from rpy2.robjects.packages import importr
stats = importr("stats")
d = stats.as_dist(m)
hc = r.hclust(d)

[注意:错误消息也暗示了rpy2中可能存在的转换错误。你能提交错误报告吗?感谢]

相关问题