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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:45:26+00:00 2026-05-31T19:45:26+00:00

I need to do a simple data conversion in R for usage with igraph.

  • 0

I need to do a simple data conversion in R for usage with igraph. My dataframe is in this format, grouped by GROUP:

    A   GROUP
1   1       a
2   2       a
3   3       a
4   4       a
5   1       b
6   3       b
7   5       b

1. How do I expand the groups to get an undirected edgelist el in this format?

    A   B
1   1   2
2   1   3
3   1   4
4   2   3
5   2   4
6   3   4
7   1   3
8   1   5
9   3   5

Note: no self-references 1-1, 2-2, 3-3, …

2. How do I count A-B occurrences and create a weighted edgelist from el?

    A   B   weight
1   1   2        1
2   1   3        2
3   1   4        1
4   2   3        1
5   2   4        1
6   3   4        1
7   1   5        1
8   3   5        1
  • 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-31T19:45:27+00:00Added an answer on May 31, 2026 at 7:45 pm

    Here is a way to get the edgelist with plyr:

    foo <- data.frame(
      A = c(1,2,3,4,1,3,5),   
      GROUP = c("a","a","a","a","b","b","b"))
    
    library("plyr")
    
    E1 <- do.call(rbind,dlply(foo,.(GROUP),function(x)t(combn(x$A,2))))
    
    E1
    

    Returns:

          [,1] [,2]
     [1,]    1    2
     [2,]    1    3
     [3,]    1    4
     [4,]    2    3
     [5,]    2    4
     [6,]    3    4
     [7,]    1    3
     [8,]    1    5
     [9,]    3    5
    

    Then to get the weights (here I use that combn puts the lowest number first):

    W <- apply(E1,1,function(x)sum(E1[,1]==x[1]&E1[,2]==x[2]))
    E2 <- cbind(E1,weight=W)
    E2 <- E2[!duplicated(E2),]
    
    E2
    

    Which returns:

             weight
    [1,] 1 2      1
    [2,] 1 3      2
    [3,] 1 4      1
    [4,] 2 3      1
    [5,] 2 4      1
    [6,] 3 4      1
    [7,] 1 5      1
    [8,] 3 5      1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to retrieve a simple page and use the data that it returns.
Following is the sample data. I need to make 3 copies of this data
1I have the following two tables (sample data) and need to be able to
I have posted my class below and with sample data. I need to pass
I need help in turning this linq expression into a linq statment. SampleData.Publishers and
How do I create unique key value in PHP? I need simple unique keys
I need a simple communication protocol between two devices (a PC and a microcontroller).
I need something simple like date , but in seconds since 1970 instead of
I need a simple application, preferably a cross-platform one, that enables sending of files
I need to pre-produce a million or two PDF files from a simple template

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.