- 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 the maximum value in each matrix stored in an R list?
To find the maximum value in each matrix 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 lapply function to find the maximum of each matrix.
Create the list of matrices
Using matrix function to create multiple matrices and stored them in a list using list function −
M1<-matrix(rpois(20,5),ncol=2) M2<-matrix(rpois(20,5),ncol=2) M3<-matrix(rpois(20,5),ncol=2) M4<-matrix(rpois(20,5),ncol=2) M5<-matrix(rpois(20,5),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,] 1 6 [2,] 8 8 [3,] 3 8 [4,] 2 9 [5,] 8 5 [6,] 7 4 [7,] 4 5 [8,] 2 3 [9,] 6 6 [10,] 2 5 [[2]] [,1] [,2] [1,] 1 4 [2,] 3 3 [3,] 6 4 [4,] 4 5 [5,] 6 5 [6,] 6 10 [7,] 4 6 [8,] 4 4 [9,] 8 6 [10,] 4 6 [[3]] [,1] [,2] [1,] 5 3 [2,] 2 4 [3,] 6 4 [4,] 5 5 [5,] 6 6 [6,] 1 7 [7,] 6 6 [8,] 4 3 [9,] 6 4 [10,] 3 6 [[4]] [,1] [,2] [1,] 5 9 [2,] 10 4 [3,] 9 5 [4,] 3 7 [5,] 4 1 [6,] 5 6 [7,] 5 3 [8,] 7 2 [9,] 6 1 [10,] 4 5 [[5]] [,1] [,2] [1,] 10 7 [2,] 4 6 [3,] 9 6 [4,] 2 4 [5,] 4 3 [6,] 8 10 [7,] 8 2 [8,] 4 4 [9,] 7 3 [10,] 5 5
Find the maximum of each matrix
Using max function along with lapply function to find the maximum of each matrix stored in List −
M1<-matrix(rpois(20,5),ncol=2) M2<-matrix(rpois(20,5),ncol=2) M3<-matrix(rpois(20,5),ncol=2) M4<-matrix(rpois(20,5),ncol=2) M5<-matrix(rpois(20,5),ncol=2) List<-list(M1,M2,M3,M4,M5) lapply(List,FUN=max)
Output
[[1]] [1] 9 [[2]] [1] 10 [[3]] [1] 7 [[4]] [1] 10 [[5]] [1] 10
- Related Articles
- How to find the maximum value for each row of all matrices stored in an R list?
- 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 find the maximum value of all matrices stored in an R list?
- How to find the maximum value for each column of a matrix in R?
- How to extract the first row of each matrix stored in a list in R?
- How to divide matrix rows by maximum value in each row excluding 0 in R?
- How to find the maximum value in an R data frame?
- How to find the mean of all matrices stored in an R list?
- How to find the coordinate of a value in an R matrix?
- Find the column number with largest value for each row in an R matrix.
- How to find the row products for each row in an R matrix?
- How to find the maximum of each row in an R data frame?
- How to find the row that has maximum number of duplicates in an R matrix?
- How to find the quartile for each value in an R vector?

Advertisements