I need to merge two dataframes x and y which have about 50 columns in common and some unique columns, and I need to keep all the rows from x.
It works if I run:
NewDataframe <- merge(x, y, by=c("ColumnA", "ColumnB", "ColumnC"),all.x=TRUE)
The issue is that there are more than 50 common columns, and I would rather avoid typing the names of all the common columns.
I have tried with:
NewDataframe <- merge(x, y, all.x=TRUE)
But the following error appears:
Error in merge.data.table(x, y, all.x = TRUE) :
Elements listed in `by` must be valid column names in x and y
Is there any way of using by
with the common columns without typing all of them, but keeping all the rows from x?
Thank you.