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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:09:08+00:00 2026-06-05T16:09:08+00:00

Here is my dataframe: name <- c(P1, P2, IndA, IndB, IndC, IndD, IndE, IndF,

  • 0

Here is my dataframe:

name <- c("P1", "P2", "IndA", "IndB", "IndC", "IndD", "IndE", "IndF", "IndG")
    A <- c(1, 3, 1, 2, 2, 5, 5, 1, 4)
    B <- c(2, 4, 3, 4, 2, 2, 6, 2, 2)
    mydf <- data.frame (name, A, B)

The following explanation illustrates what combination I want to generate and identify that is not possible combination.

Each parents (P1 and P2) has two and can contribute one to their child (Individual).

enter image description here

The parents can have same (for example 1, in the following example) and can contribute one each time.
enter image description here

Thus this becomes a combination game, the following example of combination.

enter image description here

Reciprocals are same (correct): 1 3 is same as 3 1

enter image description here

Question is: creat possible combination and find those that can not be member of combination.

   name <- c("P1", "P2", "IndA", "IndB", "IndC", "IndD", "IndE", "IndF", "IndG")
    A <- c(1, 3, 1, 2, 2, 5, 5, 1, 4)
    B <- c(2, 4, 3, 4, 2, 2, 6, 2, 2)
    mydf <- data.frame (name, A, B)

 name A B
1   P1 1 2
2   P2 3 4
3 IndA 1 3
4 IndB 2 4
5 IndC 2 2
6 IndD 5 2
7 IndE 5 6
8 IndF 1 2
9 IndG 4 2

enter image description here

Expected output:

   name A B     correct 
    1   P1 1 2   NA
    2   P2 3 4   NA
    3 IndA 1 3   TRUE
    4 IndB 2 4   TRUE
    5 IndC 2 2   FALSE
    6 IndD 5 2   FALSE
    7 IndE 5 6   FALSE
    8 IndF 1 2   FALSE
    9 IndG 4 2   TRUE

Edits: Second dataset for double check:

   name <- c("P1", "P2", "IndH", "IndI", "IndJ", "IndK")
    A <- c(1, 3, 3, 1, 4, 3)
    B <- c(1, 4, 3, 1, 1, 5)
    mydf2 <- data.frame (name, A, B)
    mydf2
   name A B Correct 
1   P1 1 1    NA
2   P2 3 4    NA
3 IndH 3 3    FALSE
4 IndI 1 1    FALSE
5 IndJ 4 1    TRUE
6 IndK 3 5    FALSE
  • 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-05T16:09:10+00:00Added an answer on June 5, 2026 at 4:09 pm

    something like

    dum.match<-rbind(expand.grid(c(mydf[1,2:3]),c(mydf[2,2:3])),expand.grid(c(mydf[2,2:3]),c(mydf[1,2:3])))
    newmydf<-cbind(mydf,paste(mydf$A,mydf$B)%in%paste(dum.match$Var1,dum.match$Var2))
    
    > newmydf
      name A B paste(mydf$A, mydf$B) %in% paste(dum.match$Var1, dum.match$Var2)
    1   P1 1 2                                                            FALSE
    2   P2 3 4                                                            FALSE
    3 IndA 1 3                                                             TRUE
    4 IndB 2 4                                                             TRUE
    5 IndC 2 2                                                            FALSE
    6 IndD 5 2                                                            FALSE
    7 IndE 5 6                                                            FALSE
    8 IndF 1 2                                                            FALSE
    9 IndG 4 2                                                             TRUE
    
    dum.match2<-rbind(expand.grid(c(mydf2[1,2:3]),c(mydf2[2,2:3])),expand.grid(c(mydf2[2,2:3]),c(mydf2[1,2:3])))
    newmydf2<-cbind(mydf2,paste(mydf2$A,mydf2$B)%in%paste(dum.match2$Var1,dum.match2$Var2))
    
    > newmydf2
      name A B paste(mydf2$A, mydf2$B) %in% paste(dum.match2$Var1, dum.match2$Var2)
    1   P1 1 1                                                                FALSE
    2   P2 3 4                                                                FALSE
    3 IndH 3 3                                                                FALSE
    4 IndI 1 1                                                                FALSE
    5 IndJ 4 1                                                                 TRUE
    6 IndK 3 5                                                                FALSE
    > 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is some example data: data = data.frame(series = c(1a, 1b, 1e), reading =
Here is the sample code, which produces interesting output: > gg<-data.frame(x=c(a,b),y=as.integer(c(1000,100000))) > gg x
How can I get a data frame's name from a list? Sure, get() gets
I see that when Hadley Wickam prints data frame here , the values which
Given a variable isolated from a data frame, how does one obtain it's name?
Here is dataset: set.seed(123) myd <- data.frame (class = rep(1:4, each = 100), yvar
I have the following data frame: Date1 Date2 Date3 Date4 Date5 1 25 April
I want make changes in big data.frame column names (names(mp)) with the help of
Most of the questions about merging data.frame in lists on SO don't quite relate
Possible Duplicate: How to sort a dataframe by column(s) in R Here is the

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.