R vegdist(jaccard):如何包含行名称进行聚类?

发布于 2024-11-03 17:12:40 字数 992 浏览 3 评论 0原文

可能的重复:
使用 Tanimoto/Jaccard 的 R 集群

输入

genename  treatment1 treatment2 treatment3
aaa       1          0          0
bbb       0          1          1
ccc       1          1          1
ddd       0          0          0

通过

d <- vegdist(mytable, method = "jaccard")

vegan.出现如下错误消息。

Error in rowSums(x, na.rm = TRUE) : 'x' must be numeric.

我输入 str(mytable),我看到

'data.frame': xxx obs of xxx variables:
$ aaa : int 1 0 0
$ bbb : int 0 1 1
$ ccc : int 1 1 1
$ ddd : int 0 0 0 

由于需要gene.name 来解释结果,我想保留 aaa、bbb、ccc 和 ddd。

我也尝试通过以下命令删除第一列,但是,这些命令中的任何一个都可以解决问题

rownames(mytable) <- mytable[,1]
mytable <-mytable[,-1] 

您介意教我如何解决这个问题吗?

Possible Duplicate:
R cluster with Tanimoto/Jaccard

Input

genename  treatment1 treatment2 treatment3
aaa       1          0          0
bbb       0          1          1
ccc       1          1          1
ddd       0          0          0

By doing

d <- vegdist(mytable, method = "jaccard")

from the package vegan. Error message as follows appears.

Error in rowSums(x, na.rm = TRUE) : 'x' must be numeric.

I type str(mytable), I see

'data.frame': xxx obs of xxx variables:
$ aaa : int 1 0 0
$ bbb : int 0 1 1
$ ccc : int 1 1 1
$ ddd : int 0 0 0 

As gene.name are needed to interprete the result, I want to keep the aaa, bbb, ccc and ddd.

I also tried to remove the first column by the following command, however, either of these commands can solve the problem

rownames(mytable) <- mytable[,1]
mytable <-mytable[,-1] 

Could you mind to teach me how to solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£噩梦荏苒 2024-11-10 17:12:40

以下是我使用名为geneRx 的 dfrm 得到的结果:

> rownames(geneRx) <-geneRx[,1]
> geneRx <-geneRx[,-1] 
> geneRx
    treatment1 treatment2 treatment3
aaa          1          0          0
bbb          0          1          1
ccc          1          1          1
ddd          0          0          0
> d <- vegdist(geneRx, method = "jaccard")
Warning message:
In vegdist(geneRx, method = "jaccard") :
  you have empty rows: their dissimilarities may be meaningless in method jaccard
> d
          aaa       bbb       ccc
bbb 1.0000000                    
ccc 0.6666667 0.3333333          
ddd 1.0000000 1.0000000 1.0000000

这是一个警告,而不是错误,而且它似乎提供了合理的信息。如果你没有接受治疗,你就无法与其他病例进行比较。行名用作标签。那么问题是什么

Here's what I get with a dfrm I named geneRx:

> rownames(geneRx) <-geneRx[,1]
> geneRx <-geneRx[,-1] 
> geneRx
    treatment1 treatment2 treatment3
aaa          1          0          0
bbb          0          1          1
ccc          1          1          1
ddd          0          0          0
> d <- vegdist(geneRx, method = "jaccard")
Warning message:
In vegdist(geneRx, method = "jaccard") :
  you have empty rows: their dissimilarities may be meaningless in method jaccard
> d
          aaa       bbb       ccc
bbb 1.0000000                    
ccc 0.6666667 0.3333333          
ddd 1.0000000 1.0000000 1.0000000

That is a warning, not an error, and it seems reasonalbly informative. If you don't have a treatment, you cannot compare to the other cases. And the rownames are used as labels. So what is the problem?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文