R/rkindex.R

Defines functions rkindex

Documented in rkindex

# $HeadURL: file:///srv/svn/sintro/pkg/sprof/R/rkindex.R $
# $Id: rkindex.R 245 2013-10-14 20:15:24Z gsawitzki $
# setwd("")
#! To Do
#!
# source('~/projects/rforge/sintro/pkg/sprof/R/rkindex.R', chdir = TRUE)

# create index from data, with gamma correction
rkindex <- function(x, 
	maxindex=length(x), 
	pwr=1, 
	ties.method="random",
	id ) {
		if (is.null(x)) stop("rkindex: x must not be NULL. Got ", deparse(substitute(x)))
		ix <- rank(x, ties.method=ties.method)-1
		rg <- range(ix)
		if (rg[2]>0) ix <- (ix/rg[2])^pwr
		ix <- ix*(maxindex-1) +1
		ix <- round(ix)
		
		
		if (missing(id)) {
			src<-deparse(substitute(x))
			if (pwr==1) pwr<-NULL else pwr <- paste0(", pwr=",pwr)
			id <- paste0(src, pwr)
			}
		attr(ix,"id") <- id;	 
		return(ix)
}

Try the sprof package in your browser

Any scripts or data that you put into this service are public.

sprof documentation built on May 2, 2019, 4:45 p.m.