- 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 find unique matrices in a list in R?
A list can contain many types of elements such as vectors, matrices, data frames etc. If we have matrices in a list then to find unique matrices in that list, we can simply use unique function. For example, if we have a list called LIST that contains matrices having some duplicate matrices then unique matrices can be extracted by using unique(LIST).
Example1
list(M1=matrix(1:25,ncol=5),M2=matrix(1:25,ncol=5),M3=matrix(1:25,ncol=5),M4=matrix(rpois(25,5),ncol=5)) List1
Output
$M1 [,1] [,2] [,3] [,4] [,5] [1,] 1 6 11 16 21 [2,] 2 7 12 17 22 [3,] 3 8 13 18 23 [4,] 4 9 14 19 24 [5,] 5 10 15 20 25 $M2 [,1] [,2] [,3] [,4] [,5] [1,] 1 6 11 16 21 [2,] 2 7 12 17 22 [3,] 3 8 13 18 23 [4,] 4 9 14 19 24 [5,] 5 10 15 20 25 $M3 [,1] [,2] [,3] [,4] [,5] [1,] 1 6 11 16 21 [2,] 2 7 12 17 22 [3,] 3 8 13 18 23 [4,] 4 9 14 19 24 [5,] 5 10 15 20 25 $M4 [,1] [,2] [,3] [,4] [,5] [1,] 2 3 4 6 5 [2,] 6 5 2 5 8 [3,] 3 5 5 6 6 [4,] 6 3 4 4 3 [5,] 6 10 4 6 7
Example
unique(List1)
Output
[[1]] [,1] [,2] [,3] [,4] [,5] [1,] 1 6 11 16 21 [2,] 2 7 12 17 22 [3,] 3 8 13 18 23 [4,] 4 9 14 19 24 [5,] 5 10 15 20 25 [[2]] [,1] [,2] [,3] [,4] [,5] [1,] 2 3 4 6 5 [2,] 6 5 2 5 8 [3,] 3 5 5 6 6 [4,] 6 3 4 4 3 [5,] 6 10 4 6 7
Example2
list(M1=matrix(rpois(25,5),ncol=5),M2=matrix(rpois(25,2),ncol=5),M3=matrix(rpois(25,2),ncol=5),M4=matrix(rpois(25,5),ncol=5)) List2
Output
$M1 [,1] [,2] [,3] [,4] [,5] [1,] 3 6 4 6 5 [2,] 4 7 2 9 5 [3,] 7 8 8 6 2 [4,] 3 9 5 7 7 [5,] 11 7 8 5 3 $M2 [,1] [,2] [,3] [,4] [,5] [1,] 3 4 3 3 1 [2,] 3 3 1 2 3 [3,] 0 0 0 0 1 [4,] 2 6 2 2 1 [5,] 2 0 5 2 0 $M3 [,1] [,2] [,3] [,4] [,5] [1,] 1 3 4 1 1 [2,] 3 1 3 1 1 [3,] 3 1 3 0 1 [4,] 0 1 1 3 4 [5,] 2 2 1 0 0 $M4 [,1] [,2] [,3] [,4] [,5] [1,] 6 4 4 4 6 [2,] 7 4 2 4 4 [3,] 5 3 5 9 5 [4,] 6 2 7 2 6 [5,] 8 3 5 5 1
Example
unique(List2)
Output
[[1]] [,1] [,2] [,3] [,4] [,5] [1,] 3 6 4 6 5 [2,] 4 7 2 9 5 [3,] 7 8 8 6 2 [4,] 3 9 5 7 7 [5,] 11 7 8 5 3 [[2]] [,1] [,2] [,3] [,4] [,5] [1,] 3 4 3 3 1 [2,] 3 3 1 2 3 [3,] 0 0 0 0 1 [4,] 2 6 2 2 1 [5,] 2 0 5 2 0 [[3]] [,1] [,2] [,3] [,4] [,5] [1,] 1 3 4 1 1 [2,] 3 1 3 1 1 [3,] 3 1 3 0 1 [4,] 0 1 1 3 4 [5,] 2 2 1 0 0 [[4]] [,1] [,2] [,3] [,4] [,5] [1,] 6 4 4 4 6 [2,] 7 4 2 4 4 [3,] 5 3 5 9 5 [4,] 6 2 7 2 6 [5,] 8 3 5 5 1
- Related Articles
- How to create a list of matrices in R?
- How to multiply matrices elements if matrices are stored in a list in R?
- How to convert matrices stored in a list into vectors in R?
- How to find the mean of all matrices stored in an R list?
- How to convert matrices stored in a list into data frames in R?
- How to subset unique values from a list in R?
- How to find the maximum value of all matrices stored in an R list?
- How to replace 0 in list of matrices to NA in R?
- How to find the maximum value for each row of all matrices stored in an R list?
- How to create a vector of matrices in R?
- How to find the dot product of two matrices in R?
- How to find the unique elements in multiple vectors in R?
- How to find the mean of corresponding elements of multiple matrices in R?
- How to find the correlation between corresponding columns of two matrices in R?
- How to multiply two matrices by elements in R?

Advertisements