cutn: Convert numeric to factor, using bins of equal cardinality

Description Usage Arguments Details Value See Also Examples

Description

This is similar to cut, except that the breakpoints are chosen such that each bin contains roughly the same number of samples.

Usage

1
cutn(x, n = 2, right = TRUE, ...)

Arguments

x

A numeric vector.

n

Integer, the (maximum) number of bins. The actual number of bins is limited by the number of unique values in x.

right

see cut

...

Further arguments passed to cut; e.g. "labels", "include.lowest".

Details

Some effort is made to return sensible values, even with repeated values that make completely evenly-sized bins impossible.

Missing values are silently ignored.

Value

A factor of the same length as x.

See Also

cut

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 
  table(cutn(1:100, n = 3))

  ## a practical demonstration:
  ## divide a cohort into two equally-sized strata according to age

  attach(ovarian)
  s <- Surv(futime, fustat)
  
  surviplot(s ~ cutn(age))

  surviplot(s ~ cutn(age, n = 3), stitle = 'Age (years)')

aroneklund/surviplot documentation built on May 10, 2019, 1:47 p.m.