

- 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 find the maximum value of all matrices stored in an R list?
To find the maximum value of all matrices stored in an R list, we can follow the below steps −
- First of all, create a list of matrices.
- Then, use max function along with unlist and lapply function to find the maximum of all matrices.
Create the list of matrices
Using matrix function to create multiple matrices and stored them in a list using list function −
M1<-matrix(sample(1:100,20),ncol=2) M2<-matrix(sample(1:100,20),ncol=2) M3<-matrix(sample(1:100,20),ncol=2) M4<-matrix(sample(1:100,20),ncol=2) M5<-matrix(sample(1:100,20),ncol=2) List<-list(M1,M2,M3,M4,M5) List
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
[[1]] [,1] [,2] [1,] 40 84 [2,] 4 48 [3,] 56 30 [4,] 9 46 [5,] 54 47 [6,] 16 88 [7,] 80 100 [8,] 32 23 [9,] 41 76 [10,] 79 52 [[2]] [,1] [,2] [1,] 59 82 [2,] 39 87 [3,] 49 48 [4,] 2 18 [5,] 19 47 [6,] 72 90 [7,] 3 29 [8,] 43 9 [9,] 45 76 [10,] 65 28 [[3]] [,1] [,2] [1,] 84 20 [2,] 42 95 [3,] 22 44 [4,] 34 52 [5,] 65 25 [6,] 1 92 [7,] 41 13 [8,] 68 97 [9,] 64 27 [10,] 50 6 [[4]] [,1] [,2] [1,] 72 29 [2,] 13 41 [3,] 36 89 [4,] 42 30 [5,] 68 3 [6,] 94 60 [7,] 70 44 [8,] 80 26 [9,] 10 84 [10,] 35 73 [[5]] [,1] [,2] [1,] 24 80 [2,] 75 18 [3,] 36 100 [4,] 69 51 [5,] 17 14 [6,] 77 6 [7,] 2 37 [8,] 96 63 [9,] 30 90 [10,] 86 47
Find the maximum of all matrices
Using max function along with unlist and lapply function to find the maximum of all matrices stored in List −
M1<-matrix(sample(1:100,20),ncol=2) M2<-matrix(sample(1:100,20),ncol=2) M3<-matrix(sample(1:100,20),ncol=2) M4<-matrix(sample(1:100,20),ncol=2) M5<-matrix(sample(1:100,20),ncol=2) List<-list(M1,M2,M3,M4,M5) max(unlist(lapply(List,FUN=max)))
Output
[1] 100
- Related Questions & Answers
- How to find the maximum value for each row of all matrices stored in an R list?
- How to find the mean of all matrices stored in an R list?
- How to find the maximum value in each matrix stored in an R list?
- 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 maximum value in an R data frame?
- How to convert matrices stored in a list into data frames in R?
- How to find unique matrices in a list in R?
- How to create a list of matrices in R?
- How to find the row means for each matrix stored in an R list?
- How to find the column means for each matrix stored in an R list?
- How to take transpose of vectors stored in an R list?
- How to change the name of data frames stored in an R list?
- How to find the maximum value of an array in JavaScript?
- How to find the dot product of two matrices in R?
Advertisements