[R] comparing matrices using max or min

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Thu Nov 6 16:59:49 CET 2008


you just need pmax() or pmin(), e.g., check this:

set.seed(123)
M1 <- matrix(rnorm(20), 4, 5)
M2 <- matrix(rnorm(20), 4, 5)
M3 <- matrix(rnorm(20), 4, 5)

M1; M2; M3
pmax(M1, M2, M3)
pmin(M1, M2, M3)


I hope it helps.

Best,
Dimitris


Diogo André Alagador wrote:
> Dear all,
>  
> I have 3 matrices with the same dimension, A,B,C and I would like to produce
> a matrix D where in each position would retrieve the max(or min) value along
> A,B,C taken from the same position.
> I guess that apply functions should fit, but for matrices objects I am not
> getting it.
>  
> thanks in advance,
>  
> Diogo André Alagador
> 
> 	[[alternative HTML version deleted]]
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014



More information about the R-help mailing list