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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:53:37+00:00 2026-06-18T16:53:37+00:00

So I have two data frame, and I want to match up one column

  • 0

So I have two data frame, and I want to match up one column in the first data frame with a second column in the other data frame.

df = data.frame(source=c("XRHxl8gq","2b790Qqv","mrgapJpQ","EsMfIbv1","ujOBob24","ujOBob24","EsMfIbv1"),
                conv=c(362,247,222,160,86,65,34), all=c(19,17,26,12,22,25,11), intent=c(47,47,74,31,58,60,0))

df2 = data.frame(name=c("Bob","David","Mark","Sara","Alice","Cara","Chad","Donna","Elaine","Gary"),
                 source_id=c("XRHxl8gq","sr354136FH","2b790Qqv","myx645TH","mrgapJpQ","EsMfI546",
                             "ujOBob24","EsMfIbv1","fMHL45ts","sefihn"))

What I want to end up with is match source with source_id so that I can insert a new column in df with the name.

> df
    source conv all intent   who
1 XRHxl8gq  362  19     47   Bob
2 2b790Qqv  247  17     47  Mark
3 mrgapJpQ  222  26     74 Alice
4 EsMfIbv1  160  12     31  Cara
5 ujOBob24   86  22     58  Chad
6 ujOBob24   65  25     60  Chad
7 EsMfIbv1   34  11      0  Cara

# find what values in both columns are similar.
both = intersect(df[,1], df2[,2]) # IN BOTH COLUMNS

# create a new column in the original data frame.
df$who = c("")

# match up source with source_id.
str(df2)
df2$name = as.character(df2$name)
df$who[df$source %in% df2$source_id] <- df2$name
df

df$who[which(df$source %in% df2$source_id)]<-as.character(df2$name)
df

Unfortunately, I can’t seem to match up the columns such that each source is matched up with the name associated with each source_id.

Can anyone help with this?

  • 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-18T16:53:38+00:00Added an answer on June 18, 2026 at 4:53 pm

    You’re looking for merge:

    merge(df,df2, by.x="source", by.y="source_id", sort=F)
    
    #     source conv all intent  name
    # 1 XRHxl8gq  362  19     47   Bob
    # 2 2b790Qqv  247  17     47  Mark
    # 3 mrgapJpQ  222  26     74 Alice
    # 4 EsMfIbv1  160  12     31 Donna
    # 5 EsMfIbv1   34  11      0 Donna
    # 6 ujOBob24   86  22     58  Chad
    # 7 ujOBob24   65  25     60  Chad
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame with two columns. First column contains categories such as
I have two data frames. First one looks like dat <- data.frame(matrix(nrow=2,ncol=3)) names(dat) <-
I have two data.frames that I want to append together. One data.frame holds past
I have a data frame with two columns. The first column defines subsets of
I have data frame with two column say a and b now I want
I have a data frame, with only one column, and I want to turn
I have two data frames with two columns each. The first column is timestamps
I'm trying to match numbers from one column to numbers in two other columns.
I have two data.frame s in R , each indexed by date. One is
I have two data.frames, one with only characters and the other one with characters

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.