[R] minimum values

Marc Schwartz MSchwartz at MedAnalytics.com
Sat Mar 20 18:05:57 CET 2004


On Sat, 2004-03-20 at 06:09, Rogério Rosa da Silva wrote:
> Hi,
> 
> In my data set I have created a matrix of distances. How can I get a list of 
> minimum value in each row?
> 
> thanks a lot,
> 
> Rogério


If your matrix is 'mat':

apply(mat, 1, min)

Example:

> mat <- matrix(rnorm(30), ncol = 3)

> mat
             [,1]        [,2]       [,3]
 [1,] -0.18136616  0.39529877 -1.4816285
 [2,]  0.05523284 -0.52171745  0.4893621
 [3,] -0.27029731 -0.86745328 -0.1918832
 [4,] -0.73901526 -0.35762159  1.2695002
 [5,] -0.11800851 -1.48057601 -0.8918780
 [6,] -1.52627381  1.30498318  1.0749069
 [7,]  0.08733351  1.17986453 -0.8514364
 [8,]  0.02248721  0.03496345 -1.0305299
 [9,]  0.72882492  1.32881042 -0.6423467
[10,] -0.20463172 -1.33260851  1.2732504

> apply(mat, 1, min)
 [1] -1.4816285 -0.5217175 -0.8674533 -0.7390153 -1.4805760 -1.5262738
 [7] -0.8514364 -1.0305299 -0.6423467 -1.3326085

See ?apply for more information

HTH,

Marc Schwartz




More information about the R-help mailing list