[R] replicating SAS's "proc rank" procedure

riskcalc leigh at rcalc.co.uk
Fri Oct 21 11:05:54 CEST 2011


Hi try this function ive written
it should be self explantory but let me know if you have any problems. 
I've only been using R for a few eeeks so apologies if its not the most
efficient!

rankit2<-function(rankvar,cuts,data,factor) {
ranker<-rankvar
ranker<-0
range<-c(1:cuts)
range2<-range/cuts
range3<-quantile(factor,range2)
over<-length(factor)



for (i in 1:over){ 
for (j in 1:cuts) {
 
if (data[[i,1]]<=range3[[j]])
{data[[i,3]]<-j
##test<-j
##print(j)
}
 if (data[[i,3]]>0)  break
}
}
out2<-data
return(out2)
}

cars$rank<-0
try2<-rankit2(rank,15,cars,cars$speed)
try2

all the best

Leigh
RCalc partner
www.RCalc.co.uk

--
View this message in context: http://r.789695.n4.nabble.com/replicating-SAS-s-proc-rank-procedure-tp820510p3924739.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list