Skip to content

Instantly share code, notes, and snippets.

@clarkfitzg
Created June 19, 2017 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkfitzg/952ad0b047b5db12c5ef4a0b6d64510a to your computer and use it in GitHub Desktop.
Save clarkfitzg/952ad0b047b5db12c5ef4a0b6d64510a to your computer and use it in GitHub Desktop.
#' Cut Into Bins
#'
#' No boundaries on the endpoints, and handles character \code{x}.
#' A little different than normal \code{\link[base]{cut}}
#'
#' @param x column to be cut
#' @param breaks define the bins
#' @param bin_names names for the result
#' @return bins factor
cutbin = function(x, breaks, bin_names)
{
bins = rep(1L, length(x))
i = 2L
for(b in breaks){
bins[x > b] = i
i = i + 1L
}
factor(bins, levels = seq_along(bin_names), labels = bin_names)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment