using graph.adjacency() in R

前端 未结 2 1703
时光说笑
时光说笑 2020-12-16 20:32

I have a sample code in R as follows:

library(igraph)
rm(list=ls())
dat=read.csv(file.choose(),header=TRUE,row.names=1,check.names=T) # read .csv file
m=as.m         


        
2条回答
  •  醉梦人生
    2020-12-16 21:16

    The problem seems to be due to the data-type of the matrix elements. graph.adjacency expects elements of type numeric. Not sure if its a bug.

    After you do,

    m <- as.matrix(dat)
    

    set its mode to numeric by:

    mode(m) <- "numeric"
    

    And then do:

    net <- graph.adjacency(m, mode = "undirected", weighted = TRUE, diag = FALSE)
    > E(net)$weight
    [1]  8  1 10  1 15  1  1  5  7  1
    

提交回复
热议问题