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

  • Home
  • SEARCH
  • 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 269757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:53:17+00:00 2026-05-11T23:53:17+00:00

I have a data.frame with 2 columns: Node A, Node B. Each entry in

  • 0

I have a data.frame with 2 columns: Node A, Node B. Each entry in the frame implies an edge in a graph between node A and B.

There must be a nice one-liner to convert this data.frame into an adjacency list. Any hints?

  • 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-11T23:53:17+00:00Added an answer on May 11, 2026 at 11:53 pm

    Quick and dirty …

    > edges <- data.frame(nodea=c(1,2,4,2,1), nodeb=c(1,2,3,4,5))
    
    > adjlist <- by(edges, edges$nodea, function(x) x$nodeb)
    
    > for (i in as.character(unique(edges$nodea))) {
    +   cat(i, ' -> ', adjlist[[i]], '\n')
    + }
    
    1  ->  1 5
    2  ->  2 4
    4  ->  3
    
    > adjlist
    edges$nodea: 1
    [1] 1 5
    ------------------------------------------------------------
    edges$nodea: 2
    [1] 2 4
    ------------------------------------------------------------
    edges$nodea: 4
    [1] 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While data frame columns must have the same number rows, is there any way
I have a data frame with 50000 rows and 200 columns. There are duplicate
I have a data frame with several columns, one of which is a factor
I have a data.frame with 2 columns dates=dates of observations for each station and
I have a data frame with multiple columns, one of which (called: drift.N) is
I have a data.frame which has multiple columns. One of the columns is time
I have a data.frame with 8 columns. One is for the list of subjects
I have a data frame that is 100 X 100. There are 30 columns
I have two data.frame objects 'x' and 'ans1', there are 500 columns in 'x'
I have 1 data.frame named A, there are 5000 columns in it. How can

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.