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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:12:10+00:00 2026-06-07T08:12:10+00:00

Table1 <- data.frame(CName = c(aa, bb, cc, dd), number = c(X11, X22, X33, X44))

  • 0
Table1 <- data.frame(CName  = c("aa", "bb", "cc", "dd"),
                     number = c("X11", "X22", "X33", "X44"))

Table2 <- data.frame(PName = c("zz", "yy", "xx", "ww"),
                     "X11" = c(5, 6, 3, 5),
                     "X22" = c(7, 5, 4, 3),
                     "X44" = c(9, 9, 1, 1))

I got Table1

  CName number
1    aa    X11
2    bb    X22
3    cc    X33
4    dd    X44

I got Table2

  PName X11 X22 X44
1    zz   5   7   9
2    yy   6   5   9
3    xx   3   4   1
4    ww   5   3   1

I want to get two files:

(1) by matching CName of Table 1 to column Heading of Table 2, I want to have a new table like this:

ResultsTable1

  PName  aa  bb  dd
1    zz   5   7   9
2    yy   6   5   9
3    xx   3   4   1
4    ww   5   3   1

I also wants to know the what is missing, i.e. In this example, cc is missing in Table2, so it is not matched.

ResultTable2

Table1:  
Table2: cc

Are there any effective way of doing these?

  • 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-07T08:12:12+00:00Added an answer on June 7, 2026 at 8:12 am

    Set the column names other than the first column of Table2 based on the values in Table1

    colnames(Table2)[-1] <- as.character(Table1[Table1[["number"]] %in% colnames(Table2)[-1], "CName"]) 
    Table2
    #  PName aa bb dd
    #1    zz  5  7  9
    #2    yy  6  5  9
    #3    xx  3  4  1
    #4    ww  5  3  1
    

    This will show what’s in Table1[["CName"]] that’s not in the new colnames of Table2

    as.character(Table1[["CName"]][!Table1[["CName"]] %in% colnames(Table2)[-1]])
    #[1] "cc"
    

    And this will show what’s in the new colnames of Table2, but not in Table1[["CName"]]

    as.character(colnames(Table2)[-1][!colnames(Table2)[-1] %in% Table1[["CName"]]]) 
    #character(0)
    

    Perhaps some simple examples of the %in% syntax will help (note that this is documented in ?match and that A %in% B is just an alternate syntax for match(A, B, nomatch=0) > 0

    A <- c("A", "B", "D", "E")
    B <- c("B", "C", "D")
    A %in% B
    #[1] FALSE  TRUE  TRUE FALSE
    !A %in% B
    #[1]  TRUE FALSE FALSE  TRUE
    A[A %in% B]
    #[1] "B" "D"
    A[!A %in% B]
    #[1] "A" "E"
    B[B %in% A]
    #[1] "B" "D"
    B[!B %in% A]
    #[1] "C"
    

    For your data, I used as.character to convert from factor to character

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

Sidebar

Related Questions

What I want to do is get the data from two different tables (table1
I need to insert data from table1 into table2. However, I would like to
I'm using LINQ to Get data from database table called table1 when using LINQ
To get rid of a column named foo in a data.frame , I can
I have a data frame with several rows and I want to create a
I have a data frame with a number of infections identified from clinical isolates
Given two data frames: df1 = data.frame(CustomerId = c(1:6), Product = c(rep(Toaster, 3), rep(Radio,
I have two csv files: csv1 <- data.frame(y=c(classA, classB, classA, classB, classA, classC), DBID=c(d1,
I have a data frame full from which I want to take the last
I got a big data table X (504x9) and a smaller data frame bzShare

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.