I have 2 data frames in R with epigenetic data. To use one of them as a train set and the other as a test set in the glmnet package, the column number if them have to match. As both of the data frames contain more than 800000 columns, I'm looking for a way to compare the names columns of the 2 data frames so that I can delete the columns that the two don't have in common. So far I just found packages and functions that compare rows of two data frames with each other. As an example, I'm looking for something like this:
df1
participant_code cg123 cg122 cg121 cg120
df2
participant_code cg123 cg122 cg121 cg119
The function would give me then e.g. a table in which it shows me which colnames differ:
colname 5 differs