How to Create an Exchange Matrix in R Last Updated : 02 Jun, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to create an exchange matrix in R Programming Language. The exchange matrix is a square matrix with ones on the anti-diagonal and zeros on all other elements. We can say that the exchange matrix is a combination of the identity matrix and the anti-diagonal matrix. We can call it a reversal matrix. Matrix: Exchange matrix: 1 0 0 0 0 1 0 1 0 0 1 0 0 1 1 1 1 0 In R, we can create an exchange matrix by using the diag() methods Syntax: diag(1, dimensions)[dimensions:1,] where, diag is used to create the diagonal elements in a matrix and dimensions represent size of the matrix. Example 1: In this example, we are creating 4*4 matrix and convert to exchange matrix. R # actual 4*4 matrix actual=diag(1, 4) # display print(actual) # create 4*4 exchange matrix # from actual matrix print(actual[4:1,]) Output: Example 2: In this example, we are creating 2*2 matrix and convert to an exchange matrix. R # actual 2*2 matrix actual=diag(1, 2) # display print(actual) # create 2*2 exchange matrix # from actual matrix print(actual[2:1,]) Output: Comment More infoAdvertise with us Next Article Create Matrix from Vectors in R S sravankumar_171fa07058 Follow Improve Article Tags : R Language R-Matrix Similar Reads How to Create a Distance Matrix in R? A distance matrix is a matrix that contains the distance between each pair of elements in a dataset. In R Programming Language, there are several functions available for creating a distance matrix such as dist(), daisy(), and vegdist() from the stats, cluster, and vegan packages respectively. Distan 8 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 How to Create Anti-Diagonal Matrix in R In this article, we will discuss how to create an anti-diagonal matrix with its working example in the R programming language. Anti-Diagonal Matrix: The anti-diagonal matrix is a square matrix where all entries are zero except for those on the anti-diagonal. That is to say, the diagonal goes from th 2 min read How to Create a Covariance Matrix in R? In this article, we will discuss how to create a Covariance Matrix in the R Programming Language.Covariance is the statistical measure that depicts the relationship between a pair of random variables that shows how the change in one variable causes changes in another variable. It is a measure of the 2 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