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]]
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
#how about this A <- rnorm(10) B <- rnorm(10) C <- rnorm(10) D <- data.frame(A,B,C) apply(D, MARGIN=1, FUN=min) On Thu, Nov 6, 2008 at 10:00 AM, Diogo Andr? Alagador <mcnda839 at mncn.csic.es> 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. > >-- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
Possibly Parallel Threads
- How to save R "clean" sessions in BATCH mode?
- an efficient pairwise matrix cell's comparison function
- Basic doubts on the use of several script files in R batch mode
- [dist]how to analise a large matrix?
- [ifelse] how to maintain a value from original matrix without probs?