【问题标题】:When converting matrix to dist object, first row disappears将矩阵转换为 dist 对象时,第一行消失
【发布时间】:2015-05-31 05:44:38
【问题描述】:

我需要将两个(仅下三角形 + 对角线值).csv 距离矩阵转换为 dist objects 以执行 Mantel test。尽管 as.dist(matrixname) 似乎有效,但我的第一行消失了,因此距离 matrix 偏移了一行。仅供参考,我的列和行标签是三字母代码而不是数字 - 这可能是个问题吗?

我使用了以下命令:

fst <- read.csv("fst.csv",row.names=1) fst.dist <- as.dist(fst)

当我读入 .csv 文件时,一切看起来都很好。

【问题讨论】:

  • 你试过diag=TRUE吗?
  • 就是这样!谢谢!

标签: r csv matrix


【解决方案1】:

您需要将diag=TRUE 添加到您的as.dist 通话中。

例如:

d <- read.table(text='0 1 2 
                      1 0 3
                      2 3 0')

as.dist(d)

#    V1 V2
# V2  1   
# V3  2  3

as.dist(d, diag=TRUE)

#    V1 V2 V3
# V1  0      
# V2  1  0   
# V3  2  3  0

【讨论】:

    猜你喜欢
    • 2013-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多