-2

Given two data tables with these columns:

dt1<- c("name")
dt2<-c("name", "alternative_name_1", "alternative_name_2", "ethnicity")

I want to find out which names are common in these two data tables. I know that I can use the merge function to merge my two data tables by common names. However, at the same time, I also need to compare the alternative names of my bigger data table with the names of my smaller data table and see if they match. How can I do that?

Carles
  • 2,731
  • 14
  • 25
tarimasa
  • 1
  • 2
  • 1
    Provide a reproducible example and show what the desired output is. see here https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example –  Jun 18 '19 at 10:31
  • read `?intersect()` – Wimpel Jun 18 '19 at 10:35
  • 1
    Hi and welcome to Stack Overflow! To improve your experience, read [how to ask](https://stackoverflow.com/help/how-to-ask) an [on-topic](https://stackoverflow.com/help/on-topic) question. You should also take a look at the [question checklist](https://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist) and [how to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). To lean more about how Stack Overflow works, [take the tour](https://stackoverflow.com/tour). – jsadev.net Jun 18 '19 at 10:37
  • Possible duplicate of [R: Counting the number of matches between multiple data frames](https://stackoverflow.com/questions/25045496/r-counting-the-number-of-matches-between-multiple-data-frames) – Jim G. Jun 18 '19 at 10:45

2 Answers2

0

library(tidyverse)

or

library(dplyr)

intersect(dt1,dt2)

this should return common occurrence from the two data frames

Community
  • 1
  • 1
vaibhav krishna
  • 267
  • 2
  • 4
0

One can try as following:

> dt1==dt2
[1]  TRUE FALSE FALSE FALSE
> intersect(dt1, dt2)
[1] "name"
Carles
  • 2,731
  • 14
  • 25