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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:56:31+00:00 2026-05-27T07:56:31+00:00

I have two data frames A and B , both of the same dimensions.

  • 0

I have two data frames A and B, both of the same dimensions. The row and column labels are not guaranteed to be identically ordered between frames.

Both frames contain values 0 and 1, with 1 indicating that a directed “edge” exists between a row and column of the frame (and, accordingly, 0 indicating no connection).

I would like to find “edges” common to both frames. In other words, I want a data frame of the same dimensions as A and B, which contain 1 values where there is a 1 at a row and column of both A and B.

Presently, I am looping through rows and columns and testing if both are 1.

This works, but I imagine there is a more efficient way of doing this. Is there a way to do the equivalent of a “bitwise AND” operation on row vectors of data frames, which returns a row vector I can stuff back into a new data frame? Or is there another more intelligent (and efficient) approach?

EDIT

Matrix multiplication is quite faster than my initial approach. Sorting was the key to making this work.

findCommonEdges <- function(edgesList) {
    edgesCount <- length(edgesList)
    print("finding common edges...")
    for (edgesIdx in 1:edgesCount) {
        print(paste("...searching against frame", edgesIdx, sep=" "))
        edges <- edgesList[[edgesIdx]]
        if (edgesIdx == 1) {
            # define commonEdges data frame as copy of first frame
            commonEdges <- edges
            next
        }
        #
        # we reorder edge data frame row and column labels 
        # to do matrix multiplication and find common edges
        #
        edges <- edges[order(rownames(commonEdges)), order(colnames(commonEdges))]
        commonEdges <- commonEdges * edges
    }
    commonEdges
}
  • 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-27T07:56:31+00:00Added an answer on May 27, 2026 at 7:56 am

    You can use normal multiplication for that! 🙂

    // generate data
    a = matrix(rbinom(100, 1, 0.5), nrow = 10)
    b = matrix(rbinom(100, 1, 0.5), nrow = 10)
    
    a * b // this is the result!
    

    You could also use logical & operator, which is the “bitwise and” you are looking for. Your expression would then look like (a & b) + 0
    (the + 0 will just convert from boolean back to integer).

    Note: with dataframes it works exactly the same way.

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

Sidebar

Related Questions

Is it possible to row bind two data frames that don't have the same
I have two data frames: A and B of the same number of columns
I have a data frame with two columns. First column contains categories such as
I have two results from a data set. I want to add both results
I have two small data frames, this_tx and last_tx . They are, in every
I have two data.frames. For examples sake let's say they look like this: df1
I have a various data.frames with columns of the same length where I am
Let's say I have two data frames. Each has a DAY, a MONTH, and
I have the following matching problem: I have two data.frames, one with an observation
I have two data frames. The one consists of three variables, namely date, strike

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.