% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_range.R
\name{get_range}
\alias{get_range}
\title{Convert levels, starting locations, or ending locations to range matrix}
\usage{
get_range(levels = NULL, start = NULL, end = NULL, delim = NULL)
}
\arguments{
\item{levels}{vector of levels.}

\item{start}{vector of starting location. \cr
The last element must be the ending location.}

\item{end}{vector of ending locations. \cr
The last element must be the ending location.}

\item{delim}{vector of delimiter locations.}
}
\value{
range: a \code{length(levels) x 2} matrix, \cr
where \code{length(levels) = length(start)-1 = length(end)}.
}
\description{
Convert levels, starting locations, or ending locations to range matrix
}
\details{
If \code{levels} is given: \cr
\code{ range <- cbind(cumsum(levels)-levels+1,cumsum(levels)) } \cr

If \code{start} is given: \cr
 \code{range <-  cbind(start[-length(start)]} \cr
    \code{, c(start[2:(length(start)-1)]-1,start[length(start)]) ) } \cr

If \code{end} is given, \cr
 \code{range <- cbind(c(1,end[1:(length(end)-1)]+1),end) } \cr

If \code{delim} is given, \cr
 \code{range <-  cbind(c(1,delim[-length(delim)]+1)} \cr
    \code{, c(delim[-length(delim)]-1,delim[length(delim)])) } \cr

 Note that \code{start[-length(start)], end} and \code{delim}
 must be strictly increasing sequence of numbers.
}
\examples{
get_range( c(3,4,2) )
get_range( start=c(1,4,8,9) )
get_range( end=c(3,7,9) )
get_range( delim=c(3,7,9) )

levels <- c(1,2,3,1)
range <- get_range( levels )
levels2 <- range[,2]-range[,1]+1
identical(levels,levels2)

}
