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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:59:51+00:00 2026-06-06T00:59:51+00:00

Possible Duplicate: How to join data frames in R (inner, outer, left, right)? This

  • 0

Possible Duplicate:
How to join data frames in R (inner, outer, left, right)?

This question nicely goes over joins in R.

And the Wikipedia article on inner join is useful.

I would like to reproduce this result in base R. I don’t think the following work:

merge(employee,department,all=T)
merge(employee,department)

because of the duplicates on the merging variable.

However, sqldf works:

library(sqldf)
sqldf("select * from employee  inner join department ON employee.DepartmentID = department.DepartmentID")

My questions are:

  1. Does this mean that merge does not perform an inner join here.

  2. How can I accomplish this join in base R.

Here are two data.frames to work with from the website and example above.

employee <- structure(list(LastName = c("Rafferty ", "Jones", "Steinberg", 
"Robinson", "Smith", "John"), DepartmentID = c("31", "33", "33", 
"34", " 34", " .")), .Names = c("LastName", "DepartmentID"), class = "data.frame", row.names = c(NA, -6L))

department <- structure(list(DepartmentID = c(31L, 33L, 34L, 35L), DepartmentName =    structure(c(4L,2L, 1L, 3L), .Label = c("Clerical", "Engineering", "Marketing", "Sales"), class = "factor")), .Names = c("DepartmentID", "DepartmentName"), class = "data.frame", row.names = c(NA, -4L))
  • 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-06T00:59:52+00:00Added an answer on June 6, 2026 at 12:59 am

    Julieth,

    Please see if this works for you. I inspected the structure of the data structures to see why the results were not what was intended.

    str(department)
    str(employee)
    employee$DepartmentID <- as.numeric(employee$DepartmentID)
    merge(employee,department)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: When or why would you use a right outer join instead of
Possible Duplicate: Three table join with joins other than INNER JOIN I'm a beginner
Possible Duplicate: In MySQL queries, why use join instead of where? Joins are always
Possible Duplicate: Difference between JOIN and INNER JOIN I have found some legacy SQL
Possible Duplicate: Performing Join Operation in Java, on a small sets of data retrieved
Possible Duplicate: Is there something wrong with joins that don't use the JOIN keyword
Possible Duplicate: SQL left join vs multiple tables on FROM line? SELECT messages.message_title, messages.message_content,
Possible Duplicate: MySQL: FULL OUTER JOIN - How do I merge one column? Real
Possible Duplicate: What's the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN
Possible Duplicate: Inner join vs Where Hello in many interviews they ask which is

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.