Swapping Rows and Columns of a Data Frame in R
Overview
One of the strengths of R is that it makes operations, which are quite difficult from the perspective of someone accustomed to programming languages, easy to implement. For instance, when using arrays you do not need to allocate memory in advance because they expand on their own, and operations such as swapping the values of variables are very easy.
Example

Let’s swap the Sepal.Width column and the Species column in the Iris dataset. The method is extremely simple. You just assign the 5th column to the 2nd column, and the 2nd column to the 5th column.

Of course, the positions of rows can be manipulated in this manner as well.
Such commonsensical and convenient operations can, on the contrary, be hard to understand for someone who got into programming with another language. If you recall how you had to create a temporary parameter and keep moving values around to swap the values of variables, R will feel all the more attractive.
