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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:17:40+00:00 2026-06-07T22:17:40+00:00

Here is data: var1 <- c(A, B, K, L, G, M, M) var2 <-

  • 0

Here is data:

var1 <- c("A", "B", "K", "L", "G", "M", "M")
var2  <- c("B", "A", "K", "L", "H", "M", "M")
mydata <- data.frame (var1, var2)
     var1 var2
1    A    B
2    B    A
3    K    K
4    L    L
5    G    H
6    M    M
7    M    M

I want to create new category variable, if value of any row are equal, that will be in same category. Thus row by row comparision (all possible need to be done).

for example mydata[1,] and mydata[2,] are equal so that they will have same value say 1, in the new variable category. One important point here to make in what I intend to do. The order of the var1, var2 can be any, means that [A, B] is same as [B, A] for [var1, var2]

Sorry for simple question I could not solve to.

Edits:
Expected output

 var1 var2   caterory
1    A    B   1 
2    B    A   1
3    K    K   2
4    L    L   3
5    G    H   4
6    M    M   5
7    M    M   6
  • 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-07T22:17:41+00:00Added an answer on June 7, 2026 at 10:17 pm
    mydata$var3<-as.factor(apply(mydata,1,function(x){paste(x[order(x)],collapse='')}))
    
    > mydata
      var1 var2 var3
    1    A    B   AB
    2    B    A   AB
    3    K    K   KK
    4    L    L   LL
    5    G    H   GH
    6    M    M   MM
    7    M    M   MM
    
    > str(mydata)
    'data.frame':   7 obs. of  3 variables:
     $ var1: Factor w/ 6 levels "A","B","G","K",..: 1 2 4 5 3 6 6
     $ var2: Factor w/ 6 levels "A","B","H","K",..: 2 1 4 5 3 6 6
     $ var3: Factor w/ 5 levels "AB","GH","KK",..: 1 1 3 4 2 5 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is my simplified data set: foo <- data.frame(var1= c(1:10), var2=rep(1:5,2),var3=rep(1:2,5),var4=rep(3:7,2) ) all together
Here is data: myd <- data.frame (var1.1 = rnorm (10, 5,2), var1.2 = rnorm
to become more specific, here is an example: > expand.grid(5, 5, c(1:4,6),c(1:4,6)) Var1 Var2
I have the following scenario: <xsl:variable name=var1 select='SOME_DATA1' /> <xsl:if test='some_condition'> <xsl:variable name=var2 >
I have created an xml file here: /data/data/com.appName/emergency.xml Now I want to access this
Data: Here is sample table(TableA) data ID StartTime EndTime 1 2012-03-22 06:00:00.000 2012-03-22 06:30:00.000
I am sending HTTP GET request and receiving data here: ssize_t numBytes = recvfrom(sock,
I'm learning assembly and I have a very basic loop here segment .data msg:
for (i = 0; i < 14; i++) { //display data here } Console.WriteLine({0},
My html is like this <div id=rsContainer> <table id=rsTable><!-- DATA HERE --></table> </div> and

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.