R/tert.R

#' tert
#' 
#' Computes the tertiles for a distribution
#' 
#' @param x A distribution
#' @return A vector indicating which tertile each data point falls in 
#' @author Alexander Hopkins
#' @export
tert <- function(x){
	q <- quantile(x,c(1/3,2/3))
	w1 <- which(x<=q[[1]])
	w2 <- which(x<=q[[2]] & x>q[[1]])
	w3 <- which(x>q[[2]])
	out <- character(length=length(x))
	out[w1] <- 1
	out[w2] <- 2
	out[w3] <- 3
	out <- factor(out,levels=c('1','2','3'))
	out
}
ahopki14/immunoSeqR documentation built on May 7, 2019, 2:54 a.m.