- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create duplicate matrices and merge them together in R?
To create duplicate matrices, we can use replicate function that will repeat the original matrix and if we want to merge those matrices together then we can use rbind with do.call. For example, if we have a matrix called M then creation of it’s one duplicate and merging them together can be done using the command −
do.call(rbind,replicate(2,M,simplify=FALSE))
Example
M<-matrix(rpois(25,5),ncol=5) M
Output
[,1] [,2] [,3] [,4] [,5] [1,] 3 5 6 8 7 [2,] 3 8 6 4 6 [3,] 8 5 5 4 7 [4,] 7 6 5 7 4 [5,] 3 3 4 4 3
do.call(rbind,replicate(2,M,simplify=FALSE))
[,1] [,2] [,3] [,4] [,5] [1,] 3 5 6 8 7 [2,] 3 8 6 4 6 [3,] 8 5 5 4 7 [4,] 7 6 5 7 4 [5,] 3 3 4 4 3 [6,] 3 5 6 8 7 [7,] 3 8 6 4 6 [8,] 8 5 5 4 7 [9,] 7 6 5 7 4 [10,] 3 3 4 4 3
do.call(rbind,replicate(3,M,simplify=FALSE))
[,1] [,2] [,3] [,4] [,5] [1,] 3 5 6 8 7 [2,] 3 8 6 4 6 [3,] 8 5 5 4 7 [4,] 7 6 5 7 4 [5,] 3 3 4 4 3 [6,] 3 5 6 8 7 [7,] 3 8 6 4 6 [8,] 8 5 5 4 7 [9,] 7 6 5 7 4 [10,] 3 3 4 4 3 [11,] 3 5 6 8 7 [12,] 3 8 6 4 6 [13,] 8 5 5 4 7 [14,] 7 6 5 7 4 [15,] 3 3 4 4 3
do.call(rbind,replicate(4,M,simplify=FALSE))
[,1] [,2] [,3] [,4] [,5] [1,] 3 5 6 8 7 [2,] 3 8 6 4 6 [3,] 8 5 5 4 7 [4,] 7 6 5 7 4 [5,] 3 3 4 4 3 [6,] 3 5 6 8 7 [7,] 3 8 6 4 6 [8,] 8 5 5 4 7 [9,] 7 6 5 7 4 [10,] 3 3 4 4 3 [11,] 3 5 6 8 7 [12,] 3 8 6 4 6 [13,] 8 5 5 4 7 [14,] 7 6 5 7 4 [15,] 3 3 4 4 3 [16,] 3 5 6 8 7 [17,] 3 8 6 4 6 [18,] 8 5 5 4 7 [19,] 7 6 5 7 4 [20,] 3 3 4 4 3
do.call(rbind,replicate(6,M,simplify=FALSE))
[,1] [,2] [,3] [,4] [,5] [1,] 3 5 6 8 7 [2,] 3 8 6 4 6 [3,] 8 5 5 4 7 [4,] 7 6 5 7 4 [5,] 3 3 4 4 3 [6,] 3 5 6 8 7 [7,] 3 8 6 4 6 [8,] 8 5 5 4 7 [9,] 7 6 5 7 4 [10,] 3 3 4 4 3 [11,] 3 5 6 8 7 [12,] 3 8 6 4 6 [13,] 8 5 5 4 7 [14,] 7 6 5 7 4 [15,] 3 3 4 4 3 [16,] 3 5 6 8 7 [17,] 3 8 6 4 6 [18,] 8 5 5 4 7 [19,] 7 6 5 7 4 [20,] 3 3 4 4 3 [21,] 3 5 6 8 7 [22,] 3 8 6 4 6 [23,] 8 5 5 4 7 [24,] 7 6 5 7 4 [25,] 3 3 4 4 3 [26,] 3 5 6 8 7 [27,] 3 8 6 4 6 [28,] 8 5 5 4 7 [29,] 7 6 5 7 4 [30,] 3 3 4 4 3
- Related Articles
- How to merge two matrices by combining rows in R?
- How to create a list of matrices in R?
- How to create a vector of matrices in R?
- How to add values in columns having same name and merge them in R?
- How to combine two matrices to create a block-diagonal matrix in R?
- MySQL Merge selects together?
- How to multiply matrices elements if matrices are stored in a list in R?
- How to merge specific elements inside an array together - JavaScript
- How to multiply two matrices by elements in R?
- How to create a duplicate column in an R data frame with different name?
- How to find unique matrices in a list in R?
- How to plot two histograms together in R?
- How to check if two matrices are equal in R?
- How to multiply corresponding values from two matrices in R?
- How to create normal random variables with specific correlation between them in R?

Advertisements