Skip to content

Commit

Permalink
Add function to cut volumes vector
Browse files Browse the repository at this point in the history
These are the volumes in Asheville. Perhaps we need other levels? Related to #8
  • Loading branch information
gregmacfarlane committed Mar 17, 2016
1 parent 00de909 commit 5ef59d2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,23 @@ rmse <- function(x, y){
pct_rmse <- function(x, y){
rmse(x, y) / mean(y) * 100
}


#' Cut volumes into pretty levels
#'
#' @param x Volume levels
#' @return A labeled factor variable of \code{length(x)} with the levels of
#' \code{x} cut into bins.
#'
cut_volumes <- function(x) {
breaks <- c(0, 5, 10, 20, 40, 60, Inf) * 1000
n <- length(breaks)
labels <- c(
paste(breaks[2:n-2], "-", breaks[3:n-1]),
paste(">", breaks[n-1])
)

cut(x, breaks = breaks, labels = labels, include.lowest = TRUE)

}

19 changes: 19 additions & 0 deletions man/cut_volumes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ef59d2

Please sign in to comment.