On 05/19/08 13:46, Jens Oldeland wrote:
> Dear All,
>
> a short and maybe simple question:
>
>
> I have to rank all values in a matrix from 0 to X,
>
>[1] [2] [3] [4]
> [1] 0.1 2 03
> [2] 50 3 31
> [3] 100 1 10
> [4] 100 2 20
>
> 0->0
> 0.1->1
> 2->2
> 3->3
> 50->4
M
> To: Jens Oldeland; [EMAIL PROTECTED]
> Subject: Re: [R] Rank Values in a Matrix
>
> If your matrix below is called aa, you could do this
>
> > matrix(rank(aa, ties='min'), ncol=ncol(aa))
> [,1] [,2] [,3] [,4]
> [1,]481 11
> [2,] 14
Hi Jens,
If the matrix you described is m.
Then, you can do
> unique(as.vector(m))
[1] 0.1 2.0 0.0 3.0 50.0 1.0 100.0
> order(unique(as.vector(m)))
[1] 3 1 6 2 4 5 7
Hope this helps :)
Naira
Jens Oldeland wrote:
Dear All,
a short and maybe simple question:
I have to rank all va
ank them. OTOH, if
you want as you have below, I think this works
rank(unique(stack(aa)[1]))-1
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Jens Oldeland
> Sent: Monday, May 19, 2008 7:47 AM
> To: [EMAIL PROTECTED]
> Subject: [
Dear All,
a short and maybe simple question:
I have to rank all values in a matrix from 0 to X,
[1] [2] [3] [4]
[1] 0.1 2 03
[2] 50 3 31
[3] 100 1 10
[4] 100 2 20
0->0
0.1->1
2->2
3->3
50->4
100->5 (X=5)
is there any function for this? i have looked in sever
5 matches
Mail list logo