将矩阵转换为dist对象时,第一行消失

时间:2015-03-27 00:51:40

标签: r csv matrix

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

我使用了以下命令:

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

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

1 个答案:

答案 0 :(得分:0)

您需要在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