#' Convert a vector of integers in to a matrix of ranges
#'
#' A function which converts a one-dimensional vector into a 2-column matrix of pairwise ranges that represent the range of numbers between subsequent values
#'
#' @param vec A vector of integers
#' @param with.max (optional) A number to use as the end point of the last range
#'
#' @return matrix whose rows contain start-end pairs from original vector
#' @importFrom utils head tail
#' @export
vec2range <- function(vec, with.max=NULL){
stopifnot(is.numeric(vec))
out = cbind(
head(vec,-1),
(tail(vec,-1)-1)
)
if(!is.null(with.max)){
out = rbind(out, c( tail(vec,1), with.max) )
}
out
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.