[R] How to rank matrix data by deciles?
Phil Spector
spector at stat.berkeley.edu
Fri May 7 01:46:29 CEST 2010
Vincent -
I think
apply(y,2,function(x)
cut(x,quantile(x,(0:10)/10),label=FALSE,include.lowest=TRUE))
will give you what you want (although you didn't use set.seed so I
can't verify it against your example.)
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spector at stat.berkeley.edu
On Thu, 6 May 2010, vincent.deluard wrote:
>
>
> Hi R users,
>
> I have a matrix of data similar to:
>
>> y=matrix(rnorm(55),ncol=5)
>
>
> I would like to know to which decile each number belongs compared to the
> numbers in its column.
>
> Say y[1,1] is the third decile among y[1:11,1] and y[2,1] is in the second
> decile
> I would like get a matrix that would return their ranks in decile, i.e.,
>
> y[1,1] -> 3
> y[2,1] -> 2
>
> Your help is much appreciated!
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-rank-matrix-data-by-deciles-tp2133496p2133496.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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