Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8845109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:39:29+00:00 2026-06-14T11:39:29+00:00

I have two adjacency matrices of a dynamic network in text files, period 1

  • 0

I have two adjacency matrices of a dynamic network in text files, period 1 and 2 in R (igraph). I’d like to color the vertices and edges that are new in the second network in green.

For example the first network could look like this:

    1   3   6   10  11 
1   NA  NA  NA  NA  NA

3   NA  NA  NA  NA  NA

6   NA  NA  NA  8.695652174 13.04347826

10  NA  NA  2.586206897 NA  3.448275862

11  NA  NA  NA  2.919708029 NA

and changes then to this second network:

    1   2   3   6   10
1   NA  NA  NA  NA  NA

2   NA  NA  NA  NA  NA

3   NA  NA  NA  NA  NA

6   NA  NA  NA  12.32091691 8.022922636

10  NA  NA  7.228915663 NA  NA

The code to read in R:

t1 <- structure(matrix(c(NA,NA,NA,NA,NA, 
                         NA,NA,NA,NA,NA, 
                         NA,NA,NA,8.695652174,13.04347826, 
                         NA,NA,2.586206897,NA,3.448275862,
                         NA,NA,NA,2.919708029,NA),nrow=5, ncol=5, byrow=TRUE),
                dimnames=list(c(1,3,6,10,11), c(1,3,6,10,11)))

t2 <- structure(matrix(c(NA,NA,NA,NA,NA, 
                         NA,NA,NA,NA,NA, 
                         NA,NA,NA,NA,NA, 
                         NA,NA,12.32091691,8.022922636,NA, 
                         NA,NA,7.228915663,NA,NA),nrow=5, ncol=5, byrow=TRUE),
                dimnames=list(c(1,2,3,6,10), c(1,2,3,6,10)))

t3 <- structure(matrix(c(NA,NA,NA,NA,NA,
NA,NA,7.2289,NA,NA,
NA,10.4798,NA,NA,NA,
NA,NA,8.1364,NA,3.8762,
NA,NA,NA,NA,NA),nrow=5, ncol=5, byrow=TRUE),
dimnames=list(c(1,3,4,6,10), c(1,3,4,6,10)))

How can I link those networks in R, so that R knows which vertices are new?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:39:30+00:00Added an answer on June 14, 2026 at 11:39 am

    Ideally the solution would be to call graph.union, but that has some bugs in the current version, so here is a workaround solution.

    You are using NA to mark missing edges, which is a bit strange, because NA means that you don’t know whether the edge is missing or not. I’ll just replace the NAs with zeros.

    t1[is.na(t1)] <- 0
    t2[is.na(t2)] <- 0
    
    g1 <- graph.adjacency(t1, weighted=TRUE)
    g2 <- graph.adjacency(t2, weighted=TRUE)
    
    ## Vertices are easy
    V(g2)$color <- ifelse(V(g2)$name %in% V(g1)$name, "black", "darkgreen")
    
    ## Edges are a bit trickier
    el1 <- apply(get.edgelist(g1), 1, paste, collapse="-")
    el2 <- apply(get.edgelist(g2), 1, paste, collapse="-")
    E(g2)$color <- ifelse(el2 %in% el1, "black", "green")
    
    plot(g2, vertex.label.color="white", vertex.label=V(g2)$name)
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to have two adjacent views, a first that is a fixed size
Have two folders with approx. 150 java property files. In a shell script, how
I have two files client.php and server.php. The client file send a HTTP request
I have two queries that find both the Zip codes, and the States for
I have table in SQL Server 2005 that contains two columns Fruit and Colour
I have two sources of clinical procedure billing information that I have added together
So I have two fieldsets, wrapped in in one label that I want to
I have two columns but the codition I would like is to be evaluated
I have two STL containers that I want to merge, removing any elements that
I have two images that I want adjacent but they appear one above the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.