get_range {lazy.tools} | R Documentation |
Convert levels, starting locations, or ending locations to range matrix
Description
Convert levels, starting locations, or ending locations to range matrix
Usage
get_range(levels = NULL, start = NULL, end = NULL, delim = NULL)
Arguments
levels |
vector of levels. |
start |
vector of starting location. |
end |
vector of ending locations. |
delim |
vector of delimiter locations. |
Details
If levels
is given:
range <- cbind(cumsum(levels)-levels+1,cumsum(levels))
If start
is given:
range <- cbind(start[-length(start)]
, c(start[2:(length(start)-1)]-1,start[length(start)]) )
If end
is given,
range <- cbind(c(1,end[1:(length(end)-1)]+1),end)
If delim
is given,
range <- cbind(c(1,delim[-length(delim)]+1)
, c(delim[-length(delim)]-1,delim[length(delim)]))
Note that start[-length(start)], end
and delim
must be strictly increasing sequence of numbers.
Value
range: a length(levels) x 2
matrix,
where length(levels) = length(start)-1 = length(end)
.
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)