Skip to content

Commit

Permalink
Fix get.expanded.adjacency
Browse files Browse the repository at this point in the history
to work if author list does not contain all authors from network
and print a warning if that is the case

Signed-off by: Leo Sendelbach <s8lesend@stud.uni-saarland.de>
  • Loading branch information
Leo-Send committed Jan 9, 2024
1 parent ddbfe68 commit ff59017
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions util-networks-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,22 @@ get.expanded.adjacency = function(network, authors, weighted = FALSE) {
## get the weighted adjacency matrix for the current network
matrix.data = igraph::get.adjacency(network, attr = "weight")
} else {
## get the unweighted adjacency matrix for the current network
## get the unweighted sparse adjacency matrix for the current network
matrix.data = igraph::get.adjacency(network)
}

## order the adjacency matrix

network.authors.num = nrow(matrix.data)
## order the adjacency matrix and filter out authors that were not in authors list
if (nrow(matrix.data) > 1) { # for a 1x1 matrix ordering does not work
matrix.data = matrix.data[order(rownames(matrix.data)), order(colnames(matrix.data))]
matrix.data = matrix.data[order((rownames(matrix.data)[rownames(matrix.data) %in% authors])),
order((rownames(matrix.data)[rownames(matrix.data) %in% authors]))]
}

if(network.authors.num > nrow(matrix.data)) {
# write a warning with the number of authors from the network that we ignore
warning.string = sprintf("The network had %d authors that will not be displayed in the matrix!",
network.authors.num - nrow(matrix.data))
warning(warning.string)
}

## save the activity data per author
Expand Down

0 comments on commit ff59017

Please sign in to comment.