0

私は対称距離行列(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'_

パイプラインに沿って移動するには、隣接行列を数値にする必要があります。何かアドバイス?もちろん、私の目標を達成するための代替方法も大歓迎です。

前もって感謝します。

4

1 に答える 1

1

data.matrix必要なものを提供する必要があります。

df <- read.table(header=F, text='
                     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  
                 ')


mat <- data.matrix(df)
is.matrix(mat)
> is.matrix(mat)
[1] TRUE
is.numeric(mat)
> is.numeric(mat)
[1] TRUE
于 2014-10-09T14:51:52.817 に答える