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 7447415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:35:47+00:00 2026-05-29T12:35:47+00:00

I would appreciate help with using decompose.graph , community detection functions from igraph and

  • 0

I would appreciate help with using decompose.graph, community detection functions from igraph and lapply.

I have an igraph object G with vertex attribute “label” and edge attribute “weight”. I want to calculate community memberships using different functions from igraph, for simplicity let it be walktrap.community.

This graph is not connected, that is why I decided to decompose it
into connected components and run walktrap.community on each component, and afterwards add a community membership vertex attribute to the original graph G.

I am doing currently the following

comps <- decompose.graph(G,min.vertices=2)
communities <- lapply(comps,walktrap.community)

At this point I get stuck since I get the list object with the structure I cannot figure out. The documentation on decompose.graph tells only that it returns list object, and when I use lapply on the result I get completely confused. Moreover, the communities are numbered from 0 in each component, and I don’t know how to supply weights parameter into walktrap.community function.

If it were not for the components, I would have done the following:

wt <- walktrap.community(G, modularity=TRUE, weights=E(G)$weight)
wmemb <- community.to.membership(G, wt$merges,steps=which.max(wt$modularity)-1)
V(G)$"walktrap" <- wmemb$membership

Could anyone please help me solve this issue? Or provide some
information/links which could help?

  • 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-05-29T12:35:50+00:00Added an answer on May 29, 2026 at 12:35 pm

    You could use a loop:

    library(igraph)
    set.seed(2)
    G <- erdos.renyi.game(100, 1/50)
    comps <- decompose.graph(G,min.vertices=2)
    length(comps)  # 2 components, in this example
    for(i in seq_along(comps)) { # For each subgraph comps[[i]]
      wt <- walktrap.community(comps[[i]], modularity=TRUE, weights=E(comps[[i]])$weight)
      wmemb <- community.to.membership(comps[[i]], wt$merges,steps=which.max(wt$modularity)-1)
      V(comps[[i]])$"walktrap" <- wmemb$membership
    }
    

    It is possible to do it with lapply and mapply, but it is less readable.

    comps <- decompose.graph(G,min.vertices=2)
    wt <- lapply( comps, function(u)
      walktrap.community(u, modularity=TRUE, weights=E(u)$weight)
    )
    wmemb <- mapply( 
      function(u,v) community.to.membership(u, v$merges,steps=which.max(v$modularity)-1),
      comps, wt,
      SIMPLIFY=FALSE
    )
    comps <- mapply( 
      function(u,v) { V(u)$"walktrap" <- v$membership; u },
      comps, wmemb,
      SIMPLIFY=FALSE
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have hit a wall here and would appreciate some help from
I would appreciate some help with something I working on and have not done
I have a problem finding references to this subject and would appreciate some help.
have small problem, and would very much appreciate help :) I should convert byte
I would appreciate some help here: What I want to do: remove &itemsperpage=10 from:
I'm baffled by the results I'm getting from FFT and would appreciate any help.
I have an issue that I would appreciate any help with. Background - I
This would be my first program using threads so would appreciate any help i
I would really appreciate some help with deleting a file from IsolatedStorage on WP7.
I would appreciate some help with using dbunit. I use postgresql9 as db. I

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.