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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:08:07+00:00 2026-05-25T23:08:07+00:00

I have two R data frame with differing dimensions. However but data frames have

  • 0

I have two R data frame with differing dimensions. However but data frames have an id column

df1:

nrow(df1)=22308

                     c1      c2       c3           pattern1.match
ENSMUSG00000000001_at 10.175115 10.175423 10.109524              0
ENSMUSG00000000003_at  2.133651  2.144733  2.106649              0
ENSMUSG00000000028_at  5.713781  5.714827  5.701983              0

df2:

                               Genes Pattern.Count
ENSMUSG00000000276 ENSMUSG00000000276_at             1
ENSMUSG00000000876 ENSMUSG00000000876_at             1
ENSMUSG00000001065 ENSMUSG00000001065_at             1
ENSMUSG00000001098 ENSMUSG00000001098_at             1

nrow(df2)=425

I would like to loop through df2, and find all genes that have pattern.count=1 and check it in df1$pattern1.match column.

Basically I would like to overwrite the fields GENES AND pattern1.match with the df2$Genes and df2$Pattern.Count. All the elements from df2$Pattern.Count are equal to one.

I wrote this function, but R freezes while looping through all these rows.

idcol <- ncol(df1)
return.frame.matches <- function(df1, df2, idcol) { 
    for (i in 1:nrow(df1)) { 
         for (j in 1:nrow(df2))
                 if(df1[i, 1] == df2[j, 1]) { 
                     df1[i, idcol] = 1
                     break
                 }    
     }
     return (df1) 
}

Is there another way of doing that without almost killing the computer?

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

    I’m not sure I get exactly what you are doing, but the following should at least get you closer.

    The first column of df1 doesn’t seem to have a name, are they rownames?

    If so,

    df1$Genes <- rownames(df1)
    

    Then you could then do a merge to create a new dataframe with the genes you require:

    merge(df1,subset(df2,Pattern.Count==1))
    

    Note they are matching on the common column Genes. I’m not sure what you want to do with the pattern1.match column, but a subset on the df1 part of merge can incorporate conditions on that.

    Edit

    Going by the extra information in the comments,

    df1$pattern1.match <- as.numeric(df1$Genes %in% df2$Genes)
    

    should achieve what you are looking for.

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

Sidebar

Related Questions

I have a data frame with two columns. First column contains categories such as
I have two data.frames. For examples sake let's say they look like this: df1
Given two data frames: df1 = data.frame(CustomerId = c(1:6), Product = c(rep(Toaster, 3), rep(Radio,
I have two data frames DF1, DF2 each with 2 vectors DF1$A DF1$B, DF2$C,
I have two data frames: A and B of the same number of columns
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 a data frame with two columns (data will not always be identical).
I have two data.frame s in R , each indexed by date. One is
I have a data.frame in R. I want to try two different conditions on

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.