What is the best way to append data using matching column names from two different data frames with differing dimensions?
Scenario:
Df1 = 350(rows)x2778(columns) Df2 = 321x2910
Df1 has <2778 columns with the exact same name as <2910 columns in Df2. -It could be 500 columns in each data frame as an example that have equivalent names
What I want to do:
Append data from df2 to df1 where the column names match. E.x.: df1's data is present in matching column and has df2's data appended to the end of the column, put underneath it so to say.
If the col names don't match, the data frame that lacks the matching name should have the name attached as a new column with NA's filling the missing space. E.x.: df1 doesn't have a column df2 has, so the column is added while maintaining order of processing.
I've tried to do this using Pandas in Python but got Index duplication errors (probably the columns). I'm looking at R now but I want to know if anyone has a simple solution.
Thanks!
CodePudding user response:
Check out merge()
from base r or bind_rows()
from dplyr.