how to sort and join two files based on First Column Id I have got two files large files like this in Tab-delimited format, trying to merge in R, do we need to sort the file before merging?
 otu &lt;- read.table(&quot;asv.txt&quot;, sep=&quot;\t&quot;, header=T, blank.lines.skip=F, check.names=F)
&gt; head(otu)
                ID                   Soil.9.S42 Soil-27.S33.L001 Soil-45.S54.L001
1 d2ec9f3b77975c0f457e4b7413b217ff         34               51               84
2 3147790f0d5a78316fb9dd64f53b9473         28               32               52
3 97aecc1f35cc1f50db507ad71dd22367         33                0                7
4 bfad6370d28182cc6304844e9bec7fb6        545              237              127
5 5fa2a987221a1d9ca416148570c18086          0                0                0
6 8e60d301122d7aa359eb6b0b00f37f62        124              143              128


&gt; taxa &lt;- read.table(&quot;taxonomy.txt&quot;, sep=&quot;\t&quot;, header=F ,stringsAsFactors=F,quote=&quot;&quot;)
&gt; head(taxa)
                  ID                     V2             V3                  V4
d2ec9f3b77975c0f457e4b7413b217ff Bacteria  Cyanobacteria    Oxyphotobacteria
3147790f0d5a78316fb9dd64f53b9473 Bacteria Proteobacteria Alphaproteobacteria
97aecc1f35cc1f50db507ad71dd22367 Bacteria Proteobacteria Gammaproteobacteria
bfad6370d28182cc6304844e9bec7fb6 Bacteria Proteobacteria Alphaproteobacteria
5fa2a987221a1d9ca416148570c18086 Bacteria Proteobacteria Alphaproteobacteria
8e60d301122d7aa359eb6b0b00f37f62 Bacteria Proteobacteria Deltaproteobacteria

Now having issue with sorting file but merge command work perfectly;
newotu &lt;- otu[order(ID),]
Error in order(ID) : object 'ID' not found
&gt; total &lt;- merge(otu,taxa,by=&quot;ID&quot;)

Thanks for your help.
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;).