R/shrink_to_weighted_network.R

Defines functions `shrink_to_weighted_network`

`shrink_to_weighted_network` <-
function(net){
  # Add a column
  net <- as.matrix(net)
  # Find duplicates
  net <- net[order(net[,1],net[,2]),]
  index <- !duplicated(net[,1:2])
  # Sum duplicates to get weights
  net <- cbind(net[index,], tapply(index, cumsum(index), length))
  return(as.tnet(net, type="weighted one-mode tnet"))
}

Try the tnet package in your browser

Any scripts or data that you put into this service are public.

tnet documentation built on Feb. 25, 2020, 1:07 a.m.