0

I would like to check which Cols are extra in the first DF but not visible in the second.

Do we have any function in dplyr perhaps which could help? It would be nice if this could list out the column names only which are surplus.

JayAr
  • 57
  • 7
  • 1
    Does this answer your question? [Compare two data.frames to find the rows in data.frame 1 that are not present in data.frame 2](https://stackoverflow.com/questions/3171426/compare-two-data-frames-to-find-the-rows-in-data-frame-1-that-are-not-present-in) – cbo Nov 20 '19 at 14:39
  • @cbo How do you think this question is related to the one you linked to? The link you posted is comparing rows between two dataframe whereas here we are comparing name of the columns. – Ronak Shah Nov 22 '19 at 04:02
  • Good point, I have re-checked the question and the link @Ronak Shah. Many answer provided there can be applied in this case even if it is not indeed strictly speaking the same problem :) – cbo Nov 22 '19 at 09:47

1 Answers1

2

We can use setdiff

setdiff(names(df1), names(df2))
#[1] "b" "c"

data

df1 <- data.frame(a = 1:5, b = 6:10, c = 12:16)
df2  <- data.frame(a = 11:15)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213