Created
June 19, 2017 20:12
-
-
Save clarkfitzg/952ad0b047b5db12c5ef4a0b6d64510a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' 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