[R] maximum value replacement

arun smartpink111 at yahoo.com
Tue Oct 29 15:27:07 CET 2013


Hi,
Try:
 sapply(seq_len(ncol(A)),function(i) {indx <- which(A[,i]%in% max(A[,i])); A[,i][indx] <- B[,i]; A[,i]})

A.K.




On Tuesday, October 29, 2013 10:16 AM, eliza botto <eliza_botto at hotmail.com> wrote:
Dear Users,
I have two matrices, one with 12 rows and 124 columns(A) and the other with 1 row and 124 column(B). i want to replace the maximum value in all columns of A with each (single) column value of B. 
How can i do it??
Thanks indeed in advance,

Eliza                           
    [[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.




More information about the R-help mailing list