Dear Chris,
If 'x' is your matrix, you could try this:
tail(sort(apply(x,1,max)),2)
HTH,
Jorge
On Sat, Sep 20, 2008 at 8:48 PM, Chris82 <rubenbauar@gmx.de> wrote:
>
> Hello R users,
>
> is there a possibility to get the relativ maximum of a matrix?
> To get the absolut maximum I use max(matrix)
>
> For example:
>
> The absolut maximum of this matrix is 6[3,6], but the relativ maximum is
> 6[3,6] and 4[7,6], because both values are the highest value in comparison
> to their eight neighbours values.
>
> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
> [1,] 1 1 2 2 2 1 1 2
> [2,] 1 2 3 3 3 4 4 3
> [3,] 3 3 3 4 4 6 5 4
> [4,] 4 4 4 3 3 4 4 3
> [5,] 3 4 4 3 3 3 2 2
> [6,] 3 3 3 3 3 3 2 2
> [7,] 2 2 2 2 2 4 2 1
> [8,] 1 1 0 0 0 0 0 0
>
> my first idea was to use this code:
>
> a <- matrix
>
> for (i in 2:7){
> for (j in 2:7){
> relmax <- a[a[i,j] > a[(i-1),(j-1)], a[(i-1),j], a[(i-1),(j+1)],
> a[i,(j-1)],
> a[i,(j+1)], a[(i+1),(j-1)], a[(i+1),j], a[(i+1),(j-1)]]
> }
> }
>
> but the code doesn't really work
>
> thanks.
>
> greets
> --
> View this message in context:
>
http://www.nabble.com/Searching-a-relativ-maximum-of-a-matrix-tp19590576p19590576.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>
[[alternative HTML version deleted]]