简体   繁体   中英

compare dataframes columns in R

I have 2 dataframes. Both of them have the same columns names, but the first one has more variables than the second one. I want to know which columns match on both DFs or which columns are in the first DF that are not in the second one

welcome to SO!

You can modify this code to help answer your question. Check out ?setdiff for more information on that command.

vars1 <- colnames(dataframe1)
vars2 <- colnames(dataframe2)

setdiff(vars1, vars2)

It seems that you want to find out the unique part of colnames(df1) and colnames(df2) ,maybe you can try gplots::venn

library(gplots)
t1 <- c("a", "b", "c")
t2 <- c("a", "b" ,"d")  # assume t1 and t2 is your column name of df1 and df2
test <- venn(list(t1,t2))

test

you got:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM