我有一个对称距离矩阵(x):
0 2.6096 2.3601 5.6109
2.6096 0 1.7045 6.8441
2.3601 1.7045 0 6.5946
5.6109 6.8441 6.5946 0
我想将其分析为图表,以计算其光谱密度。为了做到这一点,我想按照以下步骤(使用 igraph):
x_mat <- as.matrix(x,matrix.type="adjacency") #get adjacency matrix`
x_graph <- graph.adjacency(x_mat) #convert to graph
x_lap <- graph.laplacian(x_graph) #convert to laplacian graph
x_eig <- eigen(x_lap,symmetric=TRUE,only.values=TRUE)
(I'm not sure how to plot the spectral density, but I'm not even there yet)
但我从一开始就有麻烦。我可以让我的矩阵成为一个矩阵
x_mat <- as.matrix(x,matrix.type="adjacency")
is.matrix(x_mat)
[1] TRUE
x_mat
[,1]
[1,] Numeric,39204
但我不能强迫它是数字
mode(x_mat) <- "numeric"
_Error in eval(expr, envir, enclos) :
(list) object cannot be coerced to type 'double'_
我需要邻接矩阵是数字的,以便沿着我的管道移动。有什么建议吗?当然,也欢迎实现我的目标的替代方法。
提前致谢。