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

The Archive Base Latest Questions

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

Sample data: t1 <- data.frame( CName=c(334,5as4,ggg,bbb), D1=c(1, ,3,1), D2=c(3,4,5,5) ) t2 <- data.frame( PName=c(zz,yy,xx,ww),

  • 0

Sample data:

t1 <- data.frame(
  CName=c("334","5as4","ggg","bbb"), 
  D1=c(1," ",3,1), 
  D2=c(3,4,5,5)
)

t2 <- data.frame(
  PName=c("zz","yy","xx","ww"), 
  `334`=c(5,6,3,5), 
  "ggg"=c(7,5,4,3), 
  `5as4`=c(9,9,1,1),
  check.names=FALSE
)

Producing:

t1
  CName D1 D2
1   334  1  3
2  5as4     4
3   ggg  3  5
4   bbb  1  5

t2
  PName 334 ggg 5as4
1    zz   5   7    9
2    yy   6   5    9
3    xx   3   4    1
4    ww   5   3    1

I want to match the column t1$CName column to the column headings oft2.

The Desired output is:

   PName  334  ggg  5as4
     D1   1    3     
     D2   3    5    4
1    zz   5    7    9
2    yy   6    5    9
3    xx   3    4    1
4    ww   5    3    1
  • 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-07T10:22:42+00:00Added an answer on June 7, 2026 at 10:22 am

    It seems to me that you really want to merge the transpose of t1 with t2:

    Step 1: Create a transposed copy of table t1:

    tt1 <- as.data.frame(t(t1[, -1]), stringsAsFactors=FALSE)
    names(tt1) <- t1[, 1]
    tt1$PName = rownames(tt1)
    
    tt1
       334 5as4 ggg bbb PName
    D1   1        3   1    D1
    D2   3    4   5   5    D2
    

    Step 2: Merge

    merge(tt1, t2, all=TRUE, sort=FALSE)
    
      334 5as4 ggg PName  bbb
    1   1        3    D1    1
    2   3    4   5    D2    5
    3   5    9   7    zz <NA>
    4   6    9   5    yy <NA>
    5   3    1   4    xx <NA>
    6   5    1   3    ww <NA>
    

    Step 3: Now all you have to do is remove the columns you don’t need.

      334 5as4 ggg PName
    1   1        3    D1
    2   3    4   5    D2
    3   5    9   7    zz
    4   6    9   5    yy
    5   3    1   4    xx
    6   5    1   3    ww
    

    Even for your stated data size of 1000 entries this should not be a problem for R.

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

Sidebar

Related Questions

I am trying to sample a data frame from a given data frame such
Here's a sample column of my data frame, RR is a header : RR
Here is the sample code, which produces interesting output: > gg<-data.frame(x=c(a,b),y=as.integer(c(1000,100000))) > gg x
With the sample data > df1 <- data.frame(x=c(1,1,2,3), y=c(a,b,a,b)) > df1 x y 1
a.2<-sample(1:10,100,replace=T) b.2<-sample(1:100,100,replace=T) a.3<-data.frame(a.2,b.2) r<-sapply(split(a.3,a.2),function(x) which.max(x$b.2)) a.3[r,] returns the list index, not the index for
Sample datas : > mat1 = as.data.frame(matrix(c(D-J10-N1,D-J10-N2,D-J2-N1,D-J2-N2,3,6,5,7,8,4,2,3,4,1,2,3), ncol = 4)); > mat1 V1 V2
set.seed(1234) mydata <- data.frame ( individual = factor(1:10), M1a = factor (sample (c(1,2),10, replace
With df: df <- data.frame(value=abs(rnorm(100, 25, 5)), status=sample(0:1,100,replace=T)) df$value[sample(1:100,5)] <- NA I need to
I have sample data like this df <- data.frame(name = rep(letters[1:7], each = 24),
What is the most efficient way to sample a data frame under a certain

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.