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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:00:21+00:00 2026-06-17T19:00:21+00:00

I have two data.frames (here just a subset is reported since they are too

  • 0

I have two data.frames (here just a subset is reported since they are too big):

DF1:

  "G1"           "G2"  
  IL3RA          ABCC1      
  SRSF9          ADAM19     
  IL22RA2        BIK 
  UROD           ALG3
  SLC35C2        GGH
  OR12D3         SEC31A    
  OSBPL3         HIST1H2BK   

DF2:

  "S1"            "S2"     "S3"
  IL3RA            0        0      
  SRSF9            1        1       
  A1CF             0        0       
  A1CF1            1        1       
  GGH              2        0        
  HIST1H2BK        0        0          
  AAK1             0        0    

I would like the following output:

  "G1"            "S2"   "S3"     "G2"   "S2"   "S3"
  IL3RA            0      0        GGH     2      0 
  SRSF9            1      1     HIST1H2BK  0      0

I applied the function suggested to me in another similar situation. The function is:

lapply(DF1, function(x) DF2[na.omit(match(DF2[[1]], x)), ])

Surprisingly in this case it doesn’t work. I really don’t know why..I reproduced exactly the case posted in the post titled: "lop %in% over the columns of a data.frame" on my new data but nothing. Since DF1 and DF2 are too big I tried to use the cluster to have much more memory supposing that the problem was in the available memory…but nothing. The output it gives is the following:

  "S1"            "S2"     "S3"
  IL3RA            0        0      
  SRSF9            1        1       

  "S1"            "S2"     "S3"
  GGH              2        0      
  AAK1             0        0

What can I do to solve this?

  • 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-17T19:00:22+00:00Added an answer on June 17, 2026 at 7:00 pm

    This should do it.

    df1 <- structure(list(G1 = c("IL3RA", "SRSF9", "IL22RA2", "UROD", "SLC35C2", 
    "OR12D3", "OSBPL3"), G2 = c("ABCC1", "ADAM19", "BIK", "ALG3", 
    "GGH", "SEC31A", "HIST1H2BK")), .Names = c("G1", "G2"), class = "data.frame", row.names = c(NA, 
    -7L))
    df2 <- structure(list(S1 = c("IL3RA", "SRSF9", "A1CF", "A1CF1", "GGH", 
    "HIST1H2BK", "AAK1"), S2 = c(0L, 1L, 0L, 1L, 2L, 0L, 0L), S3 = c(0L, 
    1L, 0L, 1L, 0L, 0L, 0L)), .Names = c("S1", "S2", "S3"), class = "data.frame", row.names = c(NA, 
    -7L))
    
    idx1 <- match(df1$G1, df2$S1)
    idx1 <- idx1[!is.na(idx1)]
    idx2 <- match(df1$G2, df2$S1)
    idx2 <- idx2[!is.na(idx2)]
    
    out <- cbind(df2[idx1, ], df2[idx2, ])
    > out
         S1 S2 S3        S1 S2 S3
    1 IL3RA  0  0       GGH  2  0
    2 SRSF9  1  1 HIST1H2BK  0  0
    

    Edit: Solution using lapply

    out <- lapply(df1, function(x) {
        idx <- match(x, df2$S1)
        idx <- idx[!is.na(idx)]
        df2[idx, ]
    })
    # now `out` is a list of data.frames
    out.f <- do.call(cbind, out)
    # they'll be combined by columns
      G1.S1 G1.S2 G1.S3     G2.S1 G2.S2 G2.S3
    1 IL3RA     0     0       GGH     2     0
    2 SRSF9     1     1 HIST1H2BK     0     0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here are my two data frames, both have the same amount of rows which
I have two data frames with two columns each. The first column is timestamps
I am using R and I have two data frames: carrots and cucumbers. Each
I have written R code that merges two data frames based on first column
I have 2 lists, and inside each are two more lists containing data frames
I am trying to merge several data.frames into one data.frame . Since I have
I have two 2x2 data frames. Each column in each data frame is a
I have two large data frames, a and b for which identical(a,b) is TRUE
I have two data.frames in R, one of which has two columns and of
I have to merge to data frames in R. The two data frames share

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.