首页 > 解决方案 > 当我尝试在 R 中创建时间受限的集群时出现错误

问题描述

我正在尝试做一个按时间顺序排列的集群(时间受限的集群),所以我使用了 R 中的 const.clust 包。我必须构建一个连接矩阵,所以我使用了 contiguity.mat 函数。它从点之间的连接文件中读取的数据构造一个邻接矩阵。就我而言,这些点是采样器日期,不是等距的。我不确定 contiguity.mat 是否是正确的函数,因为在我发现的所有示例中,点都是坐标(用于进行受限空间聚类),而不是日期。

考虑到这一点,当我运行 contiguitiy.mat 时,R 用错误回答我。

library(mvpart)
library(const.clust)

from<-abun0[1:50,1]
from<-as.Date(from)
from<-data.frame(from)
to<- abun0[2:51,1]
to<- as.Date(to)
to<-data.frame(to)
from.to<-cbind(from,to)
links.mat.spp <- contiguity.mat(from.to, 51)

contiguity.mat(from.to, 51) 中的错误:错误:'From' > n

其他选项:

from<-abun0[1:50,1]
from<-as.Date(from)
from<-data.frame(from)
to<- abun0[2:51,1]
to<- as.Date(to)
to<-data.frame(to)
from.to<-cbind(from,to
from.to<-as.matrix(from.to)
links.mat.spp <- contiguity.mat(from.to, 51)

[<-( , j, i, value = 1)中的错误*tmp*:数组没有“dimnames”属性

我不明白我现在要做什么。请问,有人可以帮我吗?

标签: r

解决方案


我不知道const.clust-package 或contiguity.mat,但是您确定需要51作为第二个参数吗?因为from.to您现在构建的 -matrix 只有 50 行。


推荐阅读