Matrix Transpose in R Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Transpose of a matrix is an operation in which we convert the rows of the matrix in column and column of the matrix in rows. The general equation for performing the transpose of a matrix is as follows. Aij = Aji where i is not equal to j Example: Matrix M ---> [1, 8, 9 12, 6, 2 19, 42, 3] Transpose of M Output ---> [1, 12, 19 8, 6, 42, 9, 2, 3] Transpose of a Matrix can be performed in two ways: Finding the transpose by using the t() function Python3 # R program for Transpose of a Matrix # create a matrix with 2 rows # using matrix() method M <- matrix(1:6, nrow = 2) # print the original matrix print(M) # transpose of matrix # using t() function. t <- t(M) # print the transpose matrix print(t) Output: [, 1] [, 2] [, 3] [1, ] 1 3 5 [2, ] 2 4 6 [, 1] [, 2] [1, ] 1 2 [2, ] 3 4 [3, ] 5 6By iterating over each value using Loops: Python3 # create matrix with 3 rows and 3 columns Matrix = matrix(1:9, nrow = 3) # print the matrix print(Matrix) # create another matrix M2 = Matrix # Loops for Matrix Transpose for (i in 1:nrow(M2)) { # iterate over each row for (j in 1:ncol(M2)) { # iterate over each column # assign the correspondent elements # from row to column and column to row. M2[i, j] <- Matrix[j, i] } } # print the transposed matrix print(M2) Output: [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 [3,] 7 8 9 Comment More infoAdvertise with us Next Article How to create a matrix in R K KaranGupta5 Follow Improve Article Tags : R Language R-Matrix Similar Reads Transpose sparse matrix in R In R Programming language there's a package called Matrix that's great for dealing with sparse matrices. When you transpose a matrix, you swap its rows and columns. But with sparse matrices, you need to be careful to keep them efficient. What is a Sparse Matrix?Imagine a big table full of numbers, b 3 min read Transpose In R In this article, we will discuss what is Transpose and perform Transpose operations on a matrix and data frame in R Programming Language. What is Transpose?Transpose is a fundamental operation in linear algebra and data manipulation that involves flipping the rows and columns of a matrix or a data f 3 min read Reverse matrix in R A transpose of a matrix is a new matrix that is obtained by swapping the rows and columns of the original matrix. In R, you can calculate the transpose of a matrix using nested for loops to iterate through the elements and rearrange them accordingly. Transposing a matrix is a fundamental operation i 5 min read How to create a matrix in R In this article, we will discuss What is a matrix and various methods to create a matrix by using R Programming Language. What is a matrix?A matrix is a two-dimensional data set that collects rows and columns. The matrix stores the data in rows and columns format. It is possible to access the data i 3 min read Create Matrix from Vectors in R In this article, we will discuss How to convert a vector to a matrix in R Programming Language. A vector is a basic object that consists of homogeneous elements. The data type of vector can be integer, double, character, logical, complex, or raw. A vector can be created by using the c() function. Sy 6 min read Create Matrix from Vectors in R In this article, we will discuss How to convert a vector to a matrix in R Programming Language. A vector is a basic object that consists of homogeneous elements. The data type of vector can be integer, double, character, logical, complex, or raw. A vector can be created by using the c() function. Sy 6 min read Like