[R] returning the largest element in an array/matrix?

Jacques VESLOT jacques.veslot at cirad.fr
Tue Mar 7 06:09:45 CET 2006


indcol <- rep(1:ncol(mat), each=nrow(mat))[which.max(mat)]
indrow <- rep(1:nrow(mat), ncol(mat))[which.max(mat)]


indrow <- which(apply(mat==max(mat),1,sum)!=0)
indcol <- which(apply(mat==max(mat),2,sum)!=0)


Michael a écrit :

>Hi all,
>
>I want to use "which.max" to identify the maximum in a 2D array/matrix and I
>want "argmin" and return the row and column indices.
>
>But "which.max" only works for vector...
>
>Is there any convinient way to solve this problem?
>
>Thanks a lot!
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>  
>




More information about the R-help mailing list