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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:38:24+00:00 2026-06-06T23:38:24+00:00

The following is example data of my case: mark <- c(paste(M, 1:6, sep =

  • 0

The following is example data of my case:

        mark <- c(paste("M", 1:6, sep = "")); set.seed(123); 
    Ind1 <- c(sample (c("A", "B", "H"), 6, replace = T)); 
    set.seed(1234); Ind2 <- c(sample (c("A", "B", "H"), 6, replace = T));
      set.seed(12345); Ind3 <- c(sample (c("A", "B", "H"), 6, replace = T));
     set.seed (12344); 
    Ind4 <- c(sample (c("A", "B", "H"), 6, replace = T)); 
      set.seed(1234567); Ind5 <- c(sample (c("A", "B", "H"), 6, replace = T));
     myd <- data.frame (mark, Ind1, Ind2, Ind3, Ind4, Ind5)

The data

 myd
  mark Ind1 Ind2 Ind3 Ind4 Ind5
1   M1    A    A    H    A    B
2   M2    H    B    H    H    H
3   M3    B    B    H    A    H
4   M4    H    B    H    A    A
5   M5    H    H    B    A    H
6   M6    A    B    A    H    B

I want to compare all possible (triplet – 3 at a time) comparison mark for each variables (columns).

M1 & M2 & M3      -> first composition 
M1 & M2 & M4      - > second comparison 
M1 & M2 & M5
M1 & M2 & M6 
M1 & M3 & M4
M1 & M3 & M5
M1 & M3 & M6
M2 & M3 & M4
M2 & M3 & M5
M2 & M3 & M6 
......................so on 

Thus for the comparison triplet, loop would be:
T = Triplet member, T1 = first, T2 = Second, T3 = Third

nevar <- 0

 if (T1 =="A", T2 == "B", T3 == "H"){
      newvar[i] <- 0
      }
       else{
      if (T1 =="A", T2 == "B", T3 == "B"){
       newvar[i] <- 1
       } else {
         if (T1 =="A", T2 == "A", T3 == "H"){
        newvar[i] <- 1
        } else {
        newvar[i] <- "NA"
        }
        }}

How can I achieve this ?

Edit:

lets do for Ind1:

first comparison this above list
value of T1 = M1 = "A", T2 = M2 = "H", T3= M3 = "B"
              newvar = "NA"

Similarly second comparison:
T1 = M1 = "A", T2 = M2 = "H",  T3 = M4 = "H"
                newvar = "NA"

M1….M6 rownames (like variable) and I can apply this to all Ind1 ….Ind6,
Once look is ready for Ind1

  • 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-06T23:38:25+00:00Added an answer on June 6, 2026 at 11:38 pm

    To create the possible combinations you can use

    combins<-t(combn(levels(myd$mark)[myd$mark],3))
    

    you can then create a function say

    dum.fun<-function(x,myd){
    dum.match<-match(x,myd$mark)
    dum.str<-""
    dum.ans<-c()
    for(i in 2:6){
    dum.str<-paste(myd[dum.match,i],collapse="")
    dum.ans[i-1]<-NA
    if(dum.str=="ABH"){
    dum.ans[i-1]<-0}else{
    if(dum.str=="ABB"||dum.str=="AAH"){
    dum.ans[i-1]<-1
    }}
    }
    dum.ans
    }
    

    then

    out<-t(apply(combins,1,dum.fun,myd))
    cbind(combins,out)
    > head(cbind(combins,out))
         [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
    [1,] "M1" "M2" "M3" NA   "1"  NA   NA   NA  
    [2,] "M1" "M2" "M4" NA   "1"  NA   NA   NA  
    [3,] "M1" "M2" "M5" NA   "0"  NA   NA   NA  
    [4,] "M1" "M2" "M6" NA   "1"  NA   NA   NA  
    [5,] "M1" "M3" "M4" "0"  "1"  NA   NA   NA  
    [6,] "M1" "M3" "M5" "0"  "0"  NA   NA   NA  
    

    for example

    its all rather messy but hopefully I have grasped what you wanted.

    or with one call

    t(combn(levels(myd$mark)[myd$mark],3,dum.fun,myd=myd))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following html: <ul id=clients-strip> <li> <a href=http://example.com/case-studies/ data-colour=/images/made/assets/images/article-images/client-colour.png> <img src=/images/made/assets/images/article-images/client-grayscale.png alt=Client
Here is example data: myd <- data.frame (matrix (sample (c(AB, BB, AA), 100*100, replace
Given the following example data: Users +--------------------------------------------------+ | ID | First Name | Last
How can I subset the following example data frame to only return one observation
I'm applying the following example http://jsoup.org/cookbook/extracting-data/example-list-links to list links. package org.jsoup.examples; import org.jsoup.Jsoup; import
I have following structure with example data: id season_id title 1 1 Intro 2
In the following example I have two years worth of data denoted by data_2007
I have a data file that looks like the following example. I've added '%'
I'm trying to access $a using the following example: df<-data.frame(a=c(x,x,y,y),b=c(1,2,3,4)) > df a b
How can you sort the following word by the given rule? Example data is

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.