Assignment02, MICROBIAL612, Caroline Van Steendam

One of the subquestions of the first question involves sorting of metadata according to the weight of the animals. I am doing this with a couple of for-loops, but somehow R is not out-putting the desired result (for the first table: metadataSortAnimal). I explain this in the document itself, and am currently under the impression that the error lies within R and not within my code since the same piece of code is used subsequently and runs perfectly (for the second table: metadataSortSample). 

If, however, you think that I did something wrong, please let me know and I will gladly look into re-writing this code chunk. I am very curious as to what exactly is going wrong, since I feel like I have been staring at my computer screen in pure disbelief for at least a couple of hours.