Author: Team BioSakshat
Last update: June 2017
Copyright © 2017 BioSakshat, Inc. All rights reserved.
Define a function to find maximum values of every column of a matrix.
getcolmax = function(m)
{
mx=NULL;
for(i in 1:ncol(m))
{
mx[i] = max(m[,i]);
}
return(mx);
}
mat=matrix(sample(1:50, 50, replace = TRUE), nrow=10);
mat;
## [,1] [,2] [,3] [,4] [,5]
## [1,] 48 29 4 21 40
## [2,] 34 19 48 16 31
## [3,] 19 48 18 30 31
## [4,] 12 38 28 8 30
## [5,] 47 24 26 8 21
## [6,] 5 39 45 14 42
## [7,] 40 4 39 32 43
## [8,] 21 42 20 43 4
## [9,] 7 34 23 11 50
## [10,] 7 16 3 26 36
getcolmax(mat);
## [1] 48 48 48 43 50