[R] R-ish challenge for dependent ranking
baptiste auguie
ba208 at exeter.ac.uk
Mon Aug 25 17:42:28 CEST 2008
Hi
I think you want something like,
> with(ds, tapply(yn, drank1group, rank) )
also, the reshape package should do this sort of thing neatly.
Hope this helps,
baptiste
On 25 Aug 2008, at 16:10, ivo welch wrote:
> Dear R wizards: First, thanks for the notes on SQL. These pointers
> will make it a lot easier to deal with large data sets. Sorry to
> have a second short query the same day. I have been staring at this
> for a while, but I cannot figure out how to do a dependent ranking the
> R-sh way.
>
> ds= data.frame( xn=rnorm(32), yn=rnorm(32), zn=rnorm(32) )
> ds$drank1group= as.integer((rank( ds$xn )-1)/4) # ok, the first set
> of 8 groups, each with 4 elements
>
> ds$drank2.bydrank1group= ??? ## here I want within each drank1group
> the rank based on yn (from 1 to 4)
>
> something like "by(ds,drank1group, rank(ds$yn))". obviously, this
> neither works nor has same dimensional output.
>
> of course, there is a really simple, clever way to do this in
> R...except that it totally eludes me. before I start writing a hand
> iterating function, could someone please let me know how to do this?
>
> regards,
>
> /iaw
>
> ______________________________________________
> 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.
_____________________________
Baptiste Auguié
School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK
Phone: +44 1392 264187
http://newton.ex.ac.uk/research/emag
More information about the R-help
mailing list