Like cut, turn a vector of numbers into a factor

Description

Like cut, turn a vector of numbers into a factor

Usage

1
2
fancycut(x, intervals, buckets, na.bucket = NA, unmatched.bucket = NA,
  out.as.factor = TRUE)

Arguments

x

a numeric vector

intervals

a character vector of intervals

buckets

a character vector of levels for the new factor these have a 1-1 correspondence with intervals

na.bucket

what level should NA values be given?

unmatched.bucket

what level should numbers not covered by an interval be given?

out.as.factor

default is TRUE Should the resulting vector be a factor? If FALSE will return a character vector.

Examples

1
2
3
4
5
x <- round(runif(1000, 0, 10))
intervals <- c('(0,2]','(2,5)','[5,10]')
buckets <- c('Small','Medium','Large')
fc <- fancycut(x, intervals, buckets)
df <- data.frame(x, fc)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.