how to sort and join two files based on First Column Id
You should check left_join() method in dplyr package. In this way you do not need to sort the data frames, as the function automatically take care of this.
For example: merged_df &lt;- left_join(otu, taxa, by = &quot;ID&quot;).