Greetings! I have the following vector already in decreasing order: 125, 124, 111, 108, 107, 107, 105, .... I want to find out the rank, so I do the following: rank(-x, ties.method="min") Then I get the following: 1, 2, 3, 4, 5, 5, 7, .... but that is not what I want. I want it to give: 1. ,2, 3, 4, 5 ,5, 6, .... There should be no "jumps" in the sequence. How would that be possible? Thanks, Henri-Paul -- Henri-Paul Indiogine Curriculum & Instruction Texas A&M University TutorFind Learning Centre http://www.tutorfind.ca Email: hindiogine at gmail.com Skype: hindiogine
If they are already in decreasing order, you might be able to work something out like (untested): cumsum(c(1, diff(x) < 0)) Cheers, Michael On Fri, Oct 12, 2012 at 8:05 AM, Henri-Paul Indiogine <hindiogine at gmail.com> wrote:> Greetings! > > I have the following vector already in decreasing order: > > 125, 124, 111, 108, 107, 107, 105, .... > > I want to find out the rank, so I do the following: > > rank(-x, ties.method="min") > > Then I get the following: > > 1, 2, 3, 4, 5, 5, 7, .... > > but that is not what I want. I want it to give: > > 1. ,2, 3, 4, 5 ,5, 6, .... > > There should be no "jumps" in the sequence. > > How would that be possible? > > Thanks, > Henri-Paul > > -- > Henri-Paul Indiogine > > Curriculum & Instruction > Texas A&M University > TutorFind Learning Centre > http://www.tutorfind.ca > > Email: hindiogine at gmail.com > Skype: hindiogine > > ______________________________________________ > 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.
Hi Michael! 2012/10/12 R. Michael Weylandt <michael.weylandt at gmail.com>:> If they are already in decreasing order, you might be able to work > something out like (untested): > > cumsum(c(1, diff(x) < 0))Thanks seems to work. Thanks a bunch! Henri-Paul -- Henri-Paul Indiogine Curriculum & Instruction Texas A&M University TutorFind Learning Centre http://www.tutorfind.ca Email: hindiogine at gmail.com Skype: hindiogine
On Oct 12, 2012, at 1:07 AM, Henri-Paul Indiogine wrote:> Hi Michael! > > 2012/10/12 R. Michael Weylandt <michael.weylandt at gmail.com>: >> If they are already in decreasing order, you might be able to work >> something out like (untested): >> >> cumsum(c(1, diff(x) < 0)) > > Thanks seems to work. Thanks a bunch!Another strategy: cumsum(!duplicated(x)) -- David Winsemius, MD Alameda, CA, USA