R/getGraph.R

getGraph <- function(
  object, #authGraph table
  weighted = FALSE
  )
{
  stopifnot(is(object, "authGraph"))
  
  # Reset numbers:
  object$authorID <- as.numeric(as.factor((object$authorID)))
  object$articleID <- as.numeric(as.factor((object$articleID)))                                

  # Compute Adjacency:
  object$foo <- 1

  AuthxPub <- sparseMatrix(object$authorID, object$articleID)
#   AuthxPub[is.na(AuthxPub)] <- 0
  
    authAdj <- 1*(AuthxPub %*% t(AuthxPub))
    rm(AuthxPub)
    
    if (!weighted) authAdj <- 1*(authAdj>0)
    
    rownames(authAdj) <- colnames(authAdj) <- sapply(seq_len(nrow(authAdj)), function(x) object$original_name[object$authorID==x][1])
    

    return(authAdj)
}
SachaEpskamp/authGraph documentation built on May 9, 2019, 12:07 p.m.