

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- How to merge two matrices by combining rows in R?
- How to add values in columns having same name and merge them in R?
- MySQL Merge selects together?
- How to create a list of matrices in R?
- How to create a vector of matrices in R?
- Turn each character into its ASCII character code and join them together to create a number in JavaScript
- Find duplicate column values in MySQL and display them
- How to merge specific elements inside an array together - JavaScript
- Program to merge intervals and sort them in ascending order in Python
- How to combine two matrices to create a block-diagonal matrix in R?
- What are constants in Kotlin and how to create them?
- How to plot two histograms together in R?
- How to create normal random variables with specific correlation between them in R?
- What are sitemaps? How to create them?
- How to multiply matrices elements if matrices are stored in a list in R?
Advertisements