[R] replicating SAS's "proc rank" procedure
David L Carlson
dcarlson at tamu.edu
Fri Oct 21 17:56:30 CEST 2011
You can get the same results with the cut() function in R:
cut(cars$speed, breaks=quantile(cars$speed, probs=c(0:15/15)), labels=1:15,
include.lowest=TRUE)
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of riskcalc
Sent: Friday, October 21, 2011 4:06 AM
To: r-help at r-project.org
Subject: Re: [R] replicating SAS's "proc rank" procedure
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-tp820510
p3924739.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