wafflecut

0th

Percentile

Like cut, turn a vector of numbers into a factor

Like cut, turn a vector of numbers into a factor

Usage
wafflecut(x, intervals, buckets = intervals, 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.

Aliases
  • wafflecut
Examples
# NOT RUN {

wafflecut(-10:10, c('[0,2)','[2,5)','[5,10]'), c('Small','Medium','Large'))

wafflecut(-10:10, c('[0,0]','(0,2]','(2,5)','[5,10]'), c('Zero','Small','Medium','Large'))

wafflecut(-10:10, c('[0,2)','[2,5)','[5,10]'), c('Small','Medium','Large'))

wafflecut(-10:10, c('[0,0]','[0,2]','(2,5)','[5,10]'), c('Zero','Small','Medium','Large'))


# The following examples are from Richie Cotton via
# https://www.rdocumentation.org/packages/fancycut/versions/0.1.1/topics/fancycut

# Not all the values have to live in a bucket.
x <- seq.int(0, 1, 0.25)
wafflecut(x, c('(0.2, 0.3)', '(0.7, 0.8)'), c('low', 'high'))

# You can use unmatched.bucket to deal with these other intervals.
x <- seq.int(0, 1, 0.25)
wafflecut(x, c('(0.2, 0.3)', '(0.7, 0.8)'), c('low', 'high'), unmatched.bucket = 'other')

# To match NA values, use na.bucket.
x2 <- c(seq.int(0, 1, 0.25), NA)
wafflecut(x2, c('[0, 0.5)', '[0.5, 1]'), c('low', 'high'), na.bucket = 'missing')


# }
Documentation reproduced from package fancycut, version 0.1.2, License: CC0

Community examples

Looks like there are no examples yet.