I imported 8 Excel files into r and the content of the files are the same.
Now I want to merge these 8 files into one. I used the function merge. Here is my code:
> merge1 = merge(Data1.1, Data1.2, all.x = TRUE, all.y = TRUE)
> merge2 = merge(merge1, Data2.1, all.x = TRUE, all.y = TRUE)
> merge3 = merge(merge2, Data2.2, all.x = TRUE, all.y = TRUE)
> merge4 = merge(merge3, Data3.1, all.x = TRUE, all.y = TRUE)
Somehow R didn´t took all the rows from Data3.1 . The rows from merge 3 are 1.913.573. The rows from Data3.1 are in total 479.273. The rows in merge 4 are just 1.919.232 instead of 1.913.573 479.273 = 2.392.846.
Why r didn´t took all of the rows from Data3.1?
Thank u guys!!!!
CodePudding user response:
If you have same column names and same number of columns in all 8 files (as it looks like since you said 'content of the files are same'), you should use rbind function.
Newdf <- rbind(Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8)
Note that R will throw an error in either of the following scenarios:
The data frames don’t have the same number of columns. The data frames don’t have the same column names.
More information can be found here: https://www.statology.org/rbind-in-r/