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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:29:19+00:00 2026-05-26T20:29:19+00:00

I keep reading about the importance of vectorized functionality so hopefully someone can help

  • 0

I keep reading about the importance of vectorized functionality so hopefully someone can help me out here.

Say I have a data frame with two columns: name and ID. Now I also have another data frame with name and birthplace, but this data frame is much larger than the first, and contains some but not all of the names from the first data frame. How can I add a third column to the the first table that is populated with birthplaces looked up using the second table.

What I have is now is:

corresponding.birthplaces <- sapply(table1$Name, 
   function(name){return(table2$Birthplace[table2$Name==name])})

This seems inefficient. Thoughts? Does anyone know of a good book/resource for using R ‘properly’..I get the feeling that I generally do think in the least computationally effective manner conceivable.

Thanks 🙂

  • 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-05-26T20:29:19+00:00Added an answer on May 26, 2026 at 8:29 pm

    See ?merge which will perform a database link merge or join.

    Here is an example:

    set.seed(2)
    d1 <- data.frame(ID = 1:5, Name = c("Bill","Bob","Jessica","Jennifer","Robyn"))
    d2 <- data.frame(Name = c("Bill", "Gavin", "Bob", "Joris", "Jessica", "Andrie", 
                              "Jennifer","Joshua","Robyn","Iterator"),
                     Birthplace = sample(c("London","New York",
                                           "San Francisco", "Berlin",
                                           "Tokyo", "Paris"), 10, rep = TRUE))
    

    which gives:

    > d1
      ID     Name
    1  1     Bill
    2  2      Bob
    3  3  Jessica
    4  4 Jennifer
    5  5    Robyn
    > d2
           Name    Birthplace
    1      Bill      New York
    2     Gavin         Tokyo
    3       Bob        Berlin
    4     Joris      New York
    5   Jessica         Paris
    6    Andrie         Paris
    7  Jennifer        London
    8    Joshua         Paris
    9     Robyn San Francisco
    10 Iterator        Berlin
    

    Then we use merge() to do the join:

    > merge(d1, d2)
          Name ID    Birthplace
    1     Bill  1      New York
    2      Bob  2        Berlin
    3 Jennifer  4        London
    4  Jessica  3         Paris
    5    Robyn  5 San Francisco
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep reading about how biased locking, using the flag -XX:+UseBiasedLocking , can improve
I keep reading about the Backbone.js zombie (or memory leak) problem. Basically you have
I keep reading about C99 and C++11 and all these totally sweet things that
I keep reading about people who are test infected, meaning that they don't just
I keep reading about how great this new Canvas element for HTML5 is and
You'd think it would be easy, but keep reading. I can change many of
I keep reading about defficiencies and issues with languages. Specifically, I'm learning PHP and
I keep reading that an ASP.NET based web site should have custom errors enabled
One of the benefits of ASP.NET MVC I keep reading about is that it's
I have been reading articles about state management in ASP.NET for few days for

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.