Note 1: I'm using the R packages "network" and "sna"
Note 2: My original data are in edgelist format in a .csv file.
I've been looking for the best way to read in edgelist data into R. At first sight, this is simple.
data <- read.csv("file.CSV", header=F)
network <- network(data, matrix.type="edgelist", directed=F) #convert data to network object
val<-data[,3] #here are the values for my edges
set.edge.value(network, "val", val, e=1:length(network$mel))
When I ask the network to return edge values (get.edge.values), it returns the correct values.
However, when I ask summary(network)
, it just returns an adjacency matrix where all values are set to 1 (with exception of the diagonal). Even if they had the value of zero, they get a value of 1.
Moreover, trying to get something like degree(network) returns wrong results.
I have been searching for days on this. A possible solution was to use network2<-as.matrix.network(netwerk1, matrix.type="adjacency", attrname="val")
. This works. The problem, however, is that this ceases to be a network object and becomes a matrix class. As a result, I cannot add vertex attributes to the network. Converting network2 back to a network object again looses the edge values in the network.
Some help would really be appreciated.
Best, Frederik