0

I have two data frames (x and y).

When I need to join data, one of the first things I do is to look and see what the common column (field) names are for any obvious ones (such as x$id and y$id).

I can check to see how many columns x and y share like this:

library(dplyr)

colnames(x) %in% colnames(y) %>% table

Which gives:

> colnames(x) %in% colnames(y) %>% table
.
FALSE  TRUE 
    5    12

However, how can I list the names of the matching columns to see which ones they are?

Mus
  • 7,290
  • 24
  • 86
  • 130

1 Answers1

1

You can intersect the lists of column name

intersect( colnames(x),  colnames(y))
MDP89
  • 306
  • 1
  • 9