How to Transpose a Matrix Without Using t() Function in R
Last Updated :
02 Jun, 2022
In this article, we will Transpose a Matrix without using t() function in R Programming Language.
Transpose of a matrix is an operation in which we convert the rows of the matrix into columns and columns 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 ---> [1, 2, 3
4, 5, 6
7, 8, 9]
Transpose of Matrix
---> [1,4,7
2,5,8
3,6,9]
Example:
Create 3*3 matrix and transpose.
R
Matrix = matrix (1:9, nrow = 3)
print (Matrix)
M2 = Matrix
for (i in 1: nrow (M2))
{
for (j in 1: ncol (M2))
{
M2[i, j] <- Matrix[j, i]
}
}
print (M2)
|
Output:
Share your thoughts in the comments
Please Login to comment...